From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751055AbdKYEzm (ORCPT ); Fri, 24 Nov 2017 23:55:42 -0500 Received: from userp1040.oracle.com ([156.151.31.81]:32019 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750724AbdKYEzl (ORCPT ); Fri, 24 Nov 2017 23:55:41 -0500 Date: Sat, 25 Nov 2017 07:55:15 +0300 From: Dan Carpenter To: ishraq.i.ashraf@gmail.com Cc: gregkh@linuxfoundation.org, devel@driverdev.osuosl.org, insafonov@gmail.com, goudapatilk@gmail.com, linux-kernel@vger.kernel.org, himanshujha199640@gmail.com Subject: Re: [PATCH v2] staging: rtl8188eu: Fix private WEXT IOCTL calls Message-ID: <20171125045515.xsi35e4zddunumve@mwanda> References: <1511400546-10875-1-git-send-email-ishraq.i.ashraf@gmail.com> <1511573376-16102-1-git-send-email-ishraq.i.ashraf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1511573376-16102-1-git-send-email-ishraq.i.ashraf@gmail.com> User-Agent: NeoMutt/20170609 (1.8.3) X-Source-IP: aserv0022.oracle.com [141.146.126.234] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Nov 25, 2017 at 02:29:36AM +0100, ishraq.i.ashraf@gmail.com wrote: > + > + ret = 0; > + Sorry, I wasn't clear before. When I said don't initialize "ret" to zero, I just meant that in that specific case we initialized "ret" and then immediately reassigned it with: ret = some_function(); if (ret) return ret; In this case it's fine to set "ret = 0" at the start so that we don't have to do it later. > + if (copy_to_user(wrqu->data.pointer, param, wrqu->data.length)) > + ret = -EFAULT; > + > + if (pwep) > + goto err_free_pwep_param; > + > + err_free_param: > + kfree(param); > + return ret; > + > + err_free_pwep_param: > + kfree(pwep); > + kfree(param); > + return ret; > +} Hm... I said before that it's better to keep the error paths and success path separate but in this case it's probabaly simpler to merge them. This one could look like this: if (copy_to_user(wrqu->data.pointer, param, wrqu->data.length)) ret = -EFAULT; free_pwep: kfree(pwep); free_param: kfree(param); return ret; There is no need for the if (pwep) conditions, because kfree() can take a NULL pointer. Some people would just use one label but I hate that. It looks like this: free: kfree(pwep); kfree(param); return ret; The reason, I hate it is because I don't like freeing things which have not been allocated yet. If you do it the normal kernel way then you just have to keep track of the most recently allocated thing. regards, dan carpenter