Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1736408 > unrolled thread
| Started by | Thomas Meyer <thomas@m3y3r.de> |
|---|---|
| First post | 2017-09-21 08:50 +0200 |
| Last post | 2017-09-21 22:40 +0200 |
| Articles | 4 — 3 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[PATCH 4/4] ALSA: emu10k1: Cocci spatch "alloc_cast" Thomas Meyer <thomas@m3y3r.de> - 2017-09-21 08:50 +0200
Re: [PATCH 4/4] ALSA: emu10k1: Cocci spatch "alloc_cast" Takashi Iwai <tiwai@suse.de> - 2017-09-21 10:10 +0200
Re: [PATCH 4/4] ALSA: emu10k1: Cocci spatch "alloc_cast" Al Viro <viro@ZenIV.linux.org.uk> - 2017-09-21 19:40 +0200
Re: [PATCH 4/4] ALSA: emu10k1: Cocci spatch "alloc_cast" Takashi Iwai <tiwai@suse.de> - 2017-09-21 22:40 +0200
| From | Thomas Meyer <thomas@m3y3r.de> |
|---|---|
| Date | 2017-09-21 08:50 +0200 |
| Subject | [PATCH 4/4] ALSA: emu10k1: Cocci spatch "alloc_cast" |
| Message-ID | <us3t8-5H4-17@gated-at.bofh.it> |
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); if (!icode->gpr_map) goto __err_gpr; @@ -1853,7 +1853,7 @@ static int _snd_emu10k1_init_efx(struct if (!icode) return err; - icode->gpr_map = (u_int32_t __user *) kcalloc(256 + 160 + 160 + 2 * 512, + icode->gpr_map = kcalloc(256 + 160 + 160 + 2 * 512, sizeof(u_int32_t), GFP_KERNEL); if (!icode->gpr_map) goto __err_gpr;
[toc] | [next] | [standalone]
| From | Takashi Iwai <tiwai@suse.de> |
|---|---|
| Date | 2017-09-21 10:10 +0200 |
| Message-ID | <us4Ix-6IJ-3@gated-at.bofh.it> |
| In reply to | #1736408 |
On Thu, 21 Sep 2017 08:33:46 +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> No, this cast is still required because it has __user annotation. It's not about compiler warning but about sparse. thanks, Takashi
[toc] | [prev] | [next] | [standalone]
| From | Al Viro <viro@ZenIV.linux.org.uk> |
|---|---|
| Date | 2017-09-21 19:40 +0200 |
| Message-ID | <usdC9-3YA-19@gated-at.bofh.it> |
| In reply to | #1736408 |
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). FWIW, any patches of that sort anywhere near VFS are very much not welcome.
[toc] | [prev] | [next] | [standalone]
| From | Takashi Iwai <tiwai@suse.de> |
|---|---|
| Date | 2017-09-21 22:40 +0200 |
| Message-ID | <usgql-5CD-1@gated-at.bofh.it> |
| In reply to | #1736970 |
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
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web