All of lore.kernel.org
 help / color / mirror / Atom feed
From: Clemens Ladisch <clemens@ladisch.de>
To: Vicentiu Ciorbaru <cvicentiu@gmail.com>
Cc: tiwai@suse.de, alsa-devel@alsa-project.org, wfp5p@virginia.edu,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] emu10k1: Fix coccicheck warning
Date: Sun, 10 Mar 2013 20:49:12 +0100	[thread overview]
Message-ID: <513CE3B8.9020308@ladisch.de> (raw)
In-Reply-To: <CACzaYTOE=tVst3=TvUCtxpMuUOtJiHQ3o2wbgWeMvxwZy41DMw@mail.gmail.com>

Vicentiu Ciorbaru wrote:
> On Sun, Mar 10, 2013 at 6:32 PM, Clemens Ladisch <clemens@ladisch.de> wrote:
>> Vicentiu Ciorbaru wrote:
>>> Removed redundant cast of kmalloc return pointer.
>>
>>> -         (icode->gpr_map = (u_int32_t __user *)
>>> -          kcalloc(512 + 256 + 256 + 2 * 1024, sizeof(u_int32_t),
>>> -                  GFP_KERNEL)) == NULL ||
>>> +         (icode->gpr_map = kcalloc(512 + 256 + 256 + 2 * 1024,
>>> +                             sizeof(u_int32_t), GFP_KERNEL)) == NULL ||
>>
>> Why would casting to __user be redundant?
>
> My reasoning behind the patch is that the C standard does not require a
> specific cast of a void pointer in order to set it to the type of the
> member gpr_map of the struct snd_emu10k1_fx8010_code. I named it redundant
> because the compiler would cast to it anyway.

That's correct as far as the C standard is concerned.  However, __user is
a non-standard extension.

> The line also appears as a warning when running make coccicheck.

And when you remove the __user, you get a warning when running make C=x.

Both coccinelle and sparse are merely tools for finding likely bugs.
When it isn't possible to make them both happy with or without the cast,
that just shows that the code itself is badly designed.

The driver should be redesigned to not access user and kernel space
memory through the same pointer.


Regards,
Clemens

WARNING: multiple messages have this Message-ID (diff)
From: Clemens Ladisch <clemens@ladisch.de>
To: Vicentiu Ciorbaru <cvicentiu@gmail.com>
Cc: perex@perex.cz, tiwai@suse.de, wfp5p@virginia.edu,
	alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] emu10k1: Fix coccicheck warning
Date: Sun, 10 Mar 2013 20:49:12 +0100	[thread overview]
Message-ID: <513CE3B8.9020308@ladisch.de> (raw)
In-Reply-To: <CACzaYTOE=tVst3=TvUCtxpMuUOtJiHQ3o2wbgWeMvxwZy41DMw@mail.gmail.com>

Vicentiu Ciorbaru wrote:
> On Sun, Mar 10, 2013 at 6:32 PM, Clemens Ladisch <clemens@ladisch.de> wrote:
>> Vicentiu Ciorbaru wrote:
>>> Removed redundant cast of kmalloc return pointer.
>>
>>> -         (icode->gpr_map = (u_int32_t __user *)
>>> -          kcalloc(512 + 256 + 256 + 2 * 1024, sizeof(u_int32_t),
>>> -                  GFP_KERNEL)) == NULL ||
>>> +         (icode->gpr_map = kcalloc(512 + 256 + 256 + 2 * 1024,
>>> +                             sizeof(u_int32_t), GFP_KERNEL)) == NULL ||
>>
>> Why would casting to __user be redundant?
>
> My reasoning behind the patch is that the C standard does not require a
> specific cast of a void pointer in order to set it to the type of the
> member gpr_map of the struct snd_emu10k1_fx8010_code. I named it redundant
> because the compiler would cast to it anyway.

That's correct as far as the C standard is concerned.  However, __user is
a non-standard extension.

> The line also appears as a warning when running make coccicheck.

And when you remove the __user, you get a warning when running make C=x.

Both coccinelle and sparse are merely tools for finding likely bugs.
When it isn't possible to make them both happy with or without the cast,
that just shows that the code itself is badly designed.

The driver should be redesigned to not access user and kernel space
memory through the same pointer.


Regards,
Clemens

  parent reply	other threads:[~2013-03-10 19:50 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-10 12:37 [PATCH] emu10k1: Fix coccicheck warning Vicentiu Ciorbaru
2013-03-10 16:32 ` Clemens Ladisch
2013-03-10 16:32   ` Clemens Ladisch
     [not found]   ` <CACzaYTOE=tVst3=TvUCtxpMuUOtJiHQ3o2wbgWeMvxwZy41DMw@mail.gmail.com>
2013-03-10 19:49     ` Clemens Ladisch [this message]
2013-03-10 19:49       ` Clemens Ladisch
2013-03-10 19:59       ` Vicentiu Ciorbaru

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=513CE3B8.9020308@ladisch.de \
    --to=clemens@ladisch.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=cvicentiu@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tiwai@suse.de \
    --cc=wfp5p@virginia.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.