* Is casting a void ptr to something else considered bad kernel coding style
@ 2022-07-14 22:00 Steve French
2022-07-15 5:20 ` Julia Lawall
2022-07-15 8:15 ` Dan Carpenter
0 siblings, 2 replies; 3+ messages in thread
From: Steve French @ 2022-07-14 22:00 UTC (permalink / raw)
To: LKML, kernel-janitors; +Cc: Yu Zhe
For examples like this where a pointer which is (void *) is cast to
something else, is this considered bad coding style in kernel C
programming?
It may be that leaving the (unnecessary) cast in, although it is not
required for C, makes the code clearer in some cases.
Any opinions on changes to remove casts of void pointers for kernel
code (which I have recently seen suggested)?
for example:
--- a/fs/cifs/smb2pdu.c
+++ b/fs/cifs/smb2pdu.c
@@ -354,7 +354,7 @@ fill_small_buf(__le16 smb2_command, struct cifs_tcon *tcon,
void *buf,
unsigned int *total_len)
{
- struct smb2_pdu *spdu = (struct smb2_pdu *)buf;
+ struct smb2_pdu *spdu = buf;
--
Thanks,
Steve
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: Is casting a void ptr to something else considered bad kernel coding style
2022-07-14 22:00 Is casting a void ptr to something else considered bad kernel coding style Steve French
@ 2022-07-15 5:20 ` Julia Lawall
2022-07-15 8:15 ` Dan Carpenter
1 sibling, 0 replies; 3+ messages in thread
From: Julia Lawall @ 2022-07-15 5:20 UTC (permalink / raw)
To: Steve French; +Cc: LKML, kernel-janitors, Yu Zhe
On Thu, 14 Jul 2022, Steve French wrote:
> For examples like this where a pointer which is (void *) is cast to
> something else, is this considered bad coding style in kernel C
> programming?
>
> It may be that leaving the (unnecessary) cast in, although it is not
> required for C, makes the code clearer in some cases.
>
> Any opinions on changes to remove casts of void pointers for kernel
> code (which I have recently seen suggested)?
>
> for example:
>
> --- a/fs/cifs/smb2pdu.c
> +++ b/fs/cifs/smb2pdu.c
> @@ -354,7 +354,7 @@ fill_small_buf(__le16 smb2_command, struct cifs_tcon *tcon,
> void *buf,
> unsigned int *total_len)
> {
> - struct smb2_pdu *spdu = (struct smb2_pdu *)buf;
> + struct smb2_pdu *spdu = buf;
There would seem to be not much point to this (the original cast), since
the type is immediately explicit in the variable declaration.
It would also make for tiresome editing if the type should change, and it
reduces readability by adding a lot of characters that don't give useful
information.
julia
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: Is casting a void ptr to something else considered bad kernel coding style
2022-07-14 22:00 Is casting a void ptr to something else considered bad kernel coding style Steve French
2022-07-15 5:20 ` Julia Lawall
@ 2022-07-15 8:15 ` Dan Carpenter
1 sibling, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2022-07-15 8:15 UTC (permalink / raw)
To: Steve French; +Cc: LKML, kernel-janitors, Yu Zhe
On Thu, Jul 14, 2022 at 05:00:19PM -0500, Steve French wrote:
> For examples like this where a pointer which is (void *) is cast to
> something else, is this considered bad coding style in kernel C
> programming?
>
> It may be that leaving the (unnecessary) cast in, although it is not
> required for C, makes the code clearer in some cases.
>
> Any opinions on changes to remove casts of void pointers for kernel
> code (which I have recently seen suggested)?
>
Pointless casts are bad, but the churn is bad too...
regards,
dan carpenter
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-07-15 8:15 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-07-14 22:00 Is casting a void ptr to something else considered bad kernel coding style Steve French
2022-07-15 5:20 ` Julia Lawall
2022-07-15 8:15 ` Dan Carpenter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox