Received: by 10.213.65.68 with SMTP id h4csp1250656imn; Sun, 18 Mar 2018 21:40:36 -0700 (PDT) X-Google-Smtp-Source: AG47ELv8KHyqgMVQJHV0P4bRdjLfzzasFvxw8onrridUVRTW3G+EwKcAWdCB8qIgcv48ceEh0pMl X-Received: by 2002:a17:902:8bc2:: with SMTP id r2-v6mr763654plo.169.1521434436738; Sun, 18 Mar 2018 21:40:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521434436; cv=none; d=google.com; s=arc-20160816; b=WFKb0VlFKC/Am0+8rN218nrkd8m6Rpfs3AZT4B6MrDsyzHtcgZy4DAw1zi9VzOn3Nf Dgv9J6m6LT2w77jsVYWFymBth01wedQlhWkPz7uECvgyMH8jItOhceNn+gxhkOWFWKpk sKtlc3qQWBSJthZ34GvB7FPAZhttxYg3+i5Bb4tUgH09GtxNSIH6JO/BFXworPiScU9p 0ATlncRGfZJaNRNzC7GEPcGu/BrEcM9F99zrNKHU7d3GwqwKPhmJkU9MG0/8100G8jIl 7d8H2UYJeVzQsbYF5xYLWU08/IXCzZxvONHGenuygZ0qL0sq1bOPa4RRJ+8v/hyOsc26 Ic7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:dlp-filter:cms-type:user-agent :in-reply-to:content-disposition:mime-version:message-id:subject:cc :to:from:date:dkim-signature:dkim-filter:arc-authentication-results; bh=khbh6xUwak/aqPfxZWO4pxOIrq5DrROH5XFGsNNN7lg=; b=lsvaA1fobeTolc4yJmPJ4EqkWRMhm4FL7dLrTycx0jVJmaCui/5+uV4eKMO3QwrxSN IKCZF9i3Te+rxcaR2oJa2I5xGRPG4em0Lt5BcqRi/L3tVPrIZnEPgG0bL1d8aWMVFJNk 61Wy56OvwrYoS7J7qsLDWd3eGHvhCJdh7X0PtGNZPc83wuX5SErHMIIOo8dl1KCe9rtY qfXqeyDcT4p0o0NOX2EXKsdRmYXnTMR87x9AJPKJj2jn7+fDRnnrsD1q38r85SXLGRB2 7Rmdbq87X2Yd/yhXrYWIIqBX5lxVRCiahco78v0r/vnYoW1enuQ9nIO9abEWDGCWonBi kneQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=FxPgzgy1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q9-v6si11633435plr.21.2018.03.18.21.40.21; Sun, 18 Mar 2018 21:40:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=FxPgzgy1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932101AbeCSEZH (ORCPT + 99 others); Mon, 19 Mar 2018 00:25:07 -0400 Received: from mailout3.samsung.com ([203.254.224.33]:29800 "EHLO mailout3.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754511AbeCSEZB (ORCPT ); Mon, 19 Mar 2018 00:25:01 -0400 Received: from epcas1p2.samsung.com (unknown [182.195.41.46]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20180319042459epoutp035ab6b26987831697a2e128b786febee9~dN7TlC6Ti2919229192epoutp03I; Mon, 19 Mar 2018 04:24:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20180319042459epoutp035ab6b26987831697a2e128b786febee9~dN7TlC6Ti2919229192epoutp03I DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1521433499; bh=khbh6xUwak/aqPfxZWO4pxOIrq5DrROH5XFGsNNN7lg=; h=Date:From:To:Cc:Subject:In-reply-to:References:From; b=FxPgzgy1hkJC5K6vS5pj7/taokq8OiQdGID4JSB+Yi4zhvgTE23PJUYtPCYogGTay 1M4Fphz3rEf7AM9XPNL8SA6bdHUhtg3BFuk3CrAu7CiQlKFsWKC/wS3EZCG6VCA2YQ fzGFBtiJJDkVonhQVymEn9XkzKZchYxR0Ls6Qk+o= Received: from epsmges1p2.samsung.com (unknown [182.195.40.60]) by epcas1p3.samsung.com (KnoxPortal) with ESMTP id 20180319042458epcas1p3c86f160753483f38f68773c90dff8c0b~dN7Sp7y5l2209122091epcas1p3j; Mon, 19 Mar 2018 04:24:58 +0000 (GMT) Received: from epcas1p4.samsung.com ( [182.195.41.48]) by epsmges1p2.samsung.com (Symantec Messaging Gateway) with SMTP id B1.91.04136.99B3FAA5; Mon, 19 Mar 2018 13:24:57 +0900 (KST) Received: from epsmgms2p1new.samsung.com (unknown [182.195.42.142]) by epcas1p1.samsung.com (KnoxPortal) with ESMTP id 20180319042457epcas1p1a4cd48add460a6f07111e5fb1161a75d~dN7SNrU-h1250612506epcas1p1w; Mon, 19 Mar 2018 04:24:57 +0000 (GMT) X-AuditID: b6c32a36-c91ff70000001028-14-5aaf3b99da41 Received: from epmmp1.local.host ( [203.254.227.16]) by epsmgms2p1new.samsung.com (Symantec Messaging Gateway) with SMTP id 07.37.03826.99B3FAA5; Mon, 19 Mar 2018 13:24:57 +0900 (KST) Received: from ubuntu ([10.253.107.61]) by mmp1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0P5T00MBSLLL6L50@mmp1.samsung.com>; Mon, 19 Mar 2018 13:24:57 +0900 (KST) Date: Mon, 19 Mar 2018 13:24:57 +0900 From: Ji-Hun Kim To: Dan Carpenter Cc: mchehab@kernel.org, gregkh@linuxfoundation.org, arvind.yadav.cs@gmail.com, ji_hun.kim@samsung.com, linux-media@vger.kernel.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: Re: Re: [PATCH] staging: media: davinci_vpfe: add error handling on kmalloc failure Message-id: <20180319042457.GB2915@ubuntu> MIME-version: 1.0 Content-type: text/plain; charset="us-ascii" Content-disposition: inline In-reply-to: <20180316083234.yq7a4rx6w35amflu@mwanda> User-Agent: Mutt/1.5.21 (2010-09-15) X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpgk+LIzCtJLcpLzFFi42LZdljTQHem9foog71TrS2u9S5ktnj9bzqL xZ4zv9gtmhevZ7PoP72d0WLrLWmLy7vmsFn0bNjKarFs0x8mB06Pe/sOs3jsnHWX3WPTqk42 j/1z17B7fHx6i8Wjb8sqRo/Pm+QC2KNSbTJSE1NSixRS85LzUzLz0m2VvIPjneNNzQwMdQ0t LcyVFPISc1NtlVx8AnTdMnOALlNSKEvMKQUKBSQWFyvp29kU5ZeWpCpk5BeX2CpFGxoa6Rka mOsZGRnpmZjHWhmZApUkpGbseVVa0KBc8bH3ClsD40TRLkZODgkBE4kz724xdTFycQgJ7GCU uHR4EitIQkjgO6PEsiYuuKJV26GKdjNK3J/5mwXCecko8f7zRzaQKhYBVYkDp64xgthsApoS G7shbBEBHYnLnT/YQWxmgceMEj0LLEBsYYE4iTv/bjKB2LwCWhKz2qYyQ9iCEj8m32OBqNeR OHtsHSOELS3x6O8MsDmcAqYSH6bsALtUVEBFYsrJbWwgB0kIXGeT+LJ7EVADB5DjIrFvlTvE B8ISr45vYYcIS0tcOmoLEa6WWHBlBwuEXSNx8/9SJgjbWKK35wIzxFo+iXdfe1ghWnklOtqE IEo8JDqW3WCFsB0lHt34DA2So4wS15vPs05glJ2F5JtZSL6ZheSbBYzMqxjFUguKc9NTiw0L jPSKE3OLS/PS9ZLzczcxglOflt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vPtoyXefunXCve4INebeF/jAGOt24s++q1KzcMtFfxSV7IpRYijMSDbWYi4oTAYYm XUR7AgAA X-CMS-MailID: 20180319042457epcas1p1a4cd48add460a6f07111e5fb1161a75d X-Msg-Generator: CA CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20180316045841epcas2p34dc11231c65e2032e88ac7138db2daee X-RootMTR: 20180316045841epcas2p34dc11231c65e2032e88ac7138db2daee References: <1521176303-17546-1-git-send-email-ji_hun.kim@samsung.com> <20180316083234.yq7a4rx6w35amflu@mwanda> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 16, 2018 at 11:32:34AM +0300, Dan Carpenter wrote: > On Fri, Mar 16, 2018 at 01:58:23PM +0900, Ji-Hun Kim wrote: > > There is no failure checking on the param value which will be allocated > > memory by kmalloc. Add a null pointer checking statement. Then goto error: > > and return -ENOMEM error code when kmalloc is failed. > > > > Signed-off-by: Ji-Hun Kim > > --- > > drivers/staging/media/davinci_vpfe/dm365_ipipe.c | 8 ++++++++ > > 1 file changed, 8 insertions(+) > > > > diff --git a/drivers/staging/media/davinci_vpfe/dm365_ipipe.c b/drivers/staging/media/davinci_vpfe/dm365_ipipe.c > > index 6a3434c..55a922c 100644 > > --- a/drivers/staging/media/davinci_vpfe/dm365_ipipe.c > > +++ b/drivers/staging/media/davinci_vpfe/dm365_ipipe.c > > @@ -1280,6 +1280,10 @@ static int ipipe_s_config(struct v4l2_subdev *sd, struct vpfe_ipipe_config *cfg) > > > > params = kmalloc(sizeof(struct ipipe_module_params), > > GFP_KERNEL); > > + if (!params) { > > + rval = -ENOMEM; > > + goto error; > ^^^^^^^^^^ > > What does "goto error" do, do you think? It's not clear from the name. > When you have an unclear goto like this it often means the error > handling is going to be buggy. > > In this case, it does nothing so a direct "return -ENOMEM;" would be > more clear. But the rest of the error handling is buggy. Hi Dan, I appreciate for your specific feedbacks. It looks more clear. And I'd like you to see my question below. I will send the patch v2. > > 1263 static int ipipe_s_config(struct v4l2_subdev *sd, struct vpfe_ipipe_config *cfg) > 1264 { > 1265 struct vpfe_ipipe_device *ipipe = v4l2_get_subdevdata(sd); > 1266 unsigned int i; > 1267 int rval = 0; > 1268 > 1269 for (i = 0; i < ARRAY_SIZE(ipipe_modules); i++) { > 1270 unsigned int bit = 1 << i; > 1271 > 1272 if (cfg->flag & bit) { > 1273 const struct ipipe_module_if *module_if = > 1274 &ipipe_modules[i]; > 1275 struct ipipe_module_params *params; > 1276 void __user *from = *(void * __user *) > 1277 ((void *)cfg + module_if->config_offset); > 1278 size_t size; > 1279 void *to; > 1280 > 1281 params = kmalloc(sizeof(struct ipipe_module_params), > 1282 GFP_KERNEL); > > Do a direct return: > > if (!params) > return -ENOMEM; > > 1283 to = (void *)params + module_if->param_offset; > 1284 size = module_if->param_size; > 1285 > 1286 if (to && from && size) { > 1287 if (copy_from_user(to, from, size)) { > 1288 rval = -EFAULT; > 1289 break; > > The most recent thing we allocated is "params" so lets do a > "goto free_params;". We'll have to declare "params" at the start of the > function instead inside this block. > > 1290 } > 1291 rval = module_if->set(ipipe, to); > 1292 if (rval) > 1293 goto error; > > goto free_params again since params is still the most recent thing we > allocated. > > 1294 } else if (to && !from && size) { > 1295 rval = module_if->set(ipipe, NULL); > 1296 if (rval) > 1297 goto error; > > And here again goto free_params. > > 1298 } > 1299 kfree(params); > 1300 } > 1301 } > 1302 error: > 1303 return rval; > > > Change this to: > > return 0; Instead of returning rval, returning 0 would be fine? It looks that should return rval in normal case. > > free_params: > kfree(params); > return rval; > > 1304 } > > regards, > dan carpenter > > Thanks, Ji-Hun