From: Takashi Iwai <tiwai@suse.de>
To: "Al Viro" <viro@ZenIV.linux.org.uk>
Cc: "Thomas Meyer" <thomas@m3y3r.de>, <alsa-devel@alsa-project.org>,
<perex@perex.cz>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 4/4] ALSA: emu10k1: Cocci spatch "alloc_cast"
Date: Thu, 21 Sep 2017 22:39:13 +0200 [thread overview]
Message-ID: <s5h1smzdbwu.wl-tiwai@suse.de> (raw)
In-Reply-To: <20170921173914.GK32076@ZenIV.linux.org.uk>
On Thu, 21 Sep 2017 19:39:15 +0200,
Al Viro wrote:
>
> On Thu, Sep 21, 2017 at 08:33:46AM +0200, Thomas Meyer wrote:
> > Remove casting the values returned by memory allocation functions like
> > kmalloc, kzalloc, kmem_cache_alloc, kmem_cache_zalloc etc."
> > Found by coccinelle spatch "api/alloc/alloc_cast.cocci"
> >
> > Signed-off-by: Thomas Meyer <thomas@m3y3r.de>
> > ---
> >
> > diff -u -p a/sound/pci/emu10k1/emufx.c b/sound/pci/emu10k1/emufx.c
> > --- a/sound/pci/emu10k1/emufx.c
> > +++ b/sound/pci/emu10k1/emufx.c
> > @@ -1218,7 +1218,7 @@ static int _snd_emu10k1_audigy_init_efx(
> > if (!icode)
> > return err;
> >
> > - icode->gpr_map = (u_int32_t __user *) kcalloc(512 + 256 + 256 + 2 * 1024,
> > + icode->gpr_map = kcalloc(512 + 256 + 256 + 2 * 1024,
> > sizeof(u_int32_t), GFP_KERNEL);
>
> And _this_ is a wonderful example of the reasons why that kind of
> patches is bloody bad. The code you've caught is very obviously smelly -
> kcalloc() does *NOT* return a userland pointer. You are whitewashing it;
> a major "something weird is going on here" sign is gone (something weird
> in that case is hopefully a set_fs(KERNEL_DS) somewhere nearby, and it
> is asking for careful review).
Right, the code touched by the patch is a really tricky one. It uses
the same struct that contains __user pointer which is supposed to be
filled by ioctl, but in this case, the function allocates the kernel
buffer and passes it with a special flag mentioning it being a kernel
buffer later.
thanks,
Takashi
next prev parent reply other threads:[~2017-09-21 20:39 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-21 6:33 [PATCH 0/4] Cocci spatch "alloc_cast" - v4.14-rc1 Thomas Meyer
2017-09-21 6:33 ` [PATCH 4/4] ALSA: emu10k1: Cocci spatch "alloc_cast" Thomas Meyer
2017-09-21 8:00 ` Takashi Iwai
2017-09-21 17:39 ` Al Viro
2017-09-21 20:39 ` Takashi Iwai [this message]
2017-09-21 6:33 ` [PATCH 3/4] VFS: normal filesystems (and lustre): " Thomas Meyer
2017-09-21 6:33 ` [PATCH 1/4] drm/amd/powerplay: " Thomas Meyer
2017-09-21 6:55 ` Deucher, Alexander
2017-09-26 16:10 ` Alex Deucher
2017-09-21 6:33 ` [PATCH 2/4] fs: " Thomas Meyer
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=s5h1smzdbwu.wl-tiwai@suse.de \
--to=tiwai@suse.de \
--cc=alsa-devel@alsa-project.org \
--cc=linux-kernel@vger.kernel.org \
--cc=perex@perex.cz \
--cc=thomas@m3y3r.de \
--cc=viro@ZenIV.linux.org.uk \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®