Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751851AbdIUUjQ (ORCPT ); Thu, 21 Sep 2017 16:39:16 -0400 Received: from mx2.suse.de ([195.135.220.15]:34891 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751738AbdIUUjP (ORCPT ); Thu, 21 Sep 2017 16:39:15 -0400 Date: Thu, 21 Sep 2017 22:39:13 +0200 Message-ID: From: Takashi Iwai To: "Al Viro" Cc: "Thomas Meyer" , , , Subject: Re: [PATCH 4/4] ALSA: emu10k1: Cocci spatch "alloc_cast" In-Reply-To: <20170921173914.GK32076@ZenIV.linux.org.uk> References: <1505975570447-826702259-0-diffsplit-thomas@m3y3r.de> <1505975570447-568224618-4-diffsplit-thomas@m3y3r.de> <20170921173914.GK32076@ZenIV.linux.org.uk> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/25.2 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1543 Lines: 39 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 > > --- > > > > 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