LFX Mentorship application

Lukas Bulwahn lukas.bulwahn at gmail.com
Mon Aug 2 17:20:21 UTC 2021


On Mon, Aug 2, 2021 at 5:46 PM Vinesh Vilas Raut
<vineshraut2017 at gmail.com> wrote:
>

(snip)

>
> Unnecessary cast may hide bugs, see http://c-faq.com/malloc/mallocnocast.html
> casting is not require in this situation. It could be difficult to
> trace bug if any in
> there.Because compiler would  suppress the warning due to casting.
> Remove the extra casting syntax before the function call to fix this warning.
>
> {scripts/checkpatch.pl code}
> ...
> # check for pointless casting of alloc functions
>         if ($line =~ /\*\s*\)\s*$allocFunctions\b/) {
>             WARN("UNNECESSARY_CASTS",
>                  "unnecessary cast may hide bugs, see
> http://c-faq.com/malloc/mallocnocast.html\n" . $herecurr);
>         }
> ...
>
> WARNING: unnecessary cast may hide bugs, see
> http://c-faq.com/malloc/mallocnocast.html
> #1009: FILE: drivers/message/fusion/mptlan.c:1009:
> +       skb = (struct sk_buff *)dev_alloc_skb(len);
>
> WARNING: unnecessary cast may hide bugs, see
> http://c-faq.com/malloc/mallocnocast.html
> #1051: FILE: drivers/message/fusion/mptlan.c:1051:
> +       skb = (struct sk_buff *)dev_alloc_skb(len);
>
> WARNING: unnecessary cast may hide bugs, see
> http://c-faq.com/malloc/mallocnocast.html
> #863: FILE: drivers/message/fusion/mptlan.c:863:
> +       skb = (struct sk_buff *)dev_alloc_skb(len);
>

Can you do some further investigation and research what this warning is about?

E.g., Look at the commit and its commit message that introduced this
rule in checkpatch. Look in the kernel documentation for relevant
information on unnecessary casts. Possibly you also find some
discussion on the mailing list.

Summarize this information and provide some documentation on this
warning with various pointers for further reading and share that with
us.

We found 9 cases in the kernel tree:

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c:355:
WARNING:UNNECESSARY_CASTS: unnecessary cast may hide bugs, see
http://c-faq.com/malloc/mallocnocast.html
drivers/message/fusion/mptlan.c:863: WARNING:UNNECESSARY_CASTS:
unnecessary cast may hide bugs, see
http://c-faq.com/malloc/mallocnocast.html
drivers/message/fusion/mptlan.c:1009: WARNING:UNNECESSARY_CASTS:
unnecessary cast may hide bugs, see
http://c-faq.com/malloc/mallocnocast.html
drivers/message/fusion/mptlan.c:1051: WARNING:UNNECESSARY_CASTS:
unnecessary cast may hide bugs, see
http://c-faq.com/malloc/mallocnocast.html
drivers/net/ethernet/freescale/fs_enet/mac-fcc.c:150:
WARNING:UNNECESSARY_CASTS: unnecessary cast may hide bugs, see
http://c-faq.com/malloc/mallocnocast.html
drivers/net/ethernet/freescale/fs_enet/mac-fec.c:134:
WARNING:UNNECESSARY_CASTS: unnecessary cast may hide bugs, see
http://c-faq.com/malloc/mallocnocast.html
drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c:572:
WARNING:UNNECESSARY_CASTS: unnecessary cast may hide bugs, see
http://c-faq.com/malloc/mallocnocast.html
drivers/video/fbdev/goldfishfb.c:241: WARNING:UNNECESSARY_CASTS:
unnecessary cast may hide bugs, see
http://c-faq.com/malloc/mallocnocast.html
include/rdma/ib_verbs.h:2272: WARNING:UNNECESSARY_CASTS: unnecessary
cast may hide bugs, see http://c-faq.com/malloc/mallocnocast.html

Can you please check which of these cases should be refactored (so the
checkpatch warning points to a valid suggestion to refactor the code)
or if checkpatch is wrong with its suggestion and why?

If the code in drivers/message/fusion/mptlan.c shall be refactored:
Can you provide a patch that addresses this issue?

You can find various hints on how to create your first kernel patches on
https://www.kernel.org/doc/html/latest/process/submitting-patches.html.

Please first only send your first patches only to the
linux-kernel-mentees list, Dwaipayan and me, NOT to the official linux
kernel mailing lists that get_maintainers.pl suggests.

Thanks,

Lukas


More information about the Linux-kernel-mentees mailing list