Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp447987ybv; Wed, 19 Feb 2020 02:52:59 -0800 (PST) X-Google-Smtp-Source: APXvYqy5u8oICjWlz66bf7g+HP2/G1jh1D1/EbuZ3USFtE5M+Kay9NI5M7E/4qgic9u3/GQfYSQe X-Received: by 2002:aca:5a04:: with SMTP id o4mr4167699oib.113.1582109578984; Wed, 19 Feb 2020 02:52:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582109578; cv=none; d=google.com; s=arc-20160816; b=sSJvx6RfOy9GcXmjbRWR6uiR/O8it8h0NIndso41HKkaSMN914Mtk8OJ9DUCgGE/lF MgKuVpumfRjWa2VTPcXcFv0SdfYVAgRtxUPz6GYpdeiX4MClhS0lq1+ExIvip38m6lR0 ZbaoBS3Hf2JH/89JObpmijavIT3A94QAxrAhr4OlnQz5bNkXrotrY+1+cf2ozYV8gc/O IjVAVy9y+ghDQ7MkOgL5T7VMpucDJhJYbUw4468dY195AjlSb52HFWtla4H473gct5lx IaX2a8Gps8fa/Q7UPCXBseWQi2aH3/dpO9ahVVu4b6597ymkJ1jfcfjMurqXziVq16TK f2Uw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=lt0NY5ib1Jfzy6tElePJc/SbaXVWZpjySCmieUMPpiA=; b=Eu8ZEhXnf+pIKwkuYL0sqFz0Ee/dr2X6BDVbYNnx3ogAQ69Fq/fKRAYFLYAqeMkze/ WVSQhmFHbgTudfUI85l1syciQ3EADtMV5t4e1DmzqfYCME1ATyt3LAgtSQ0w0/fDCMDb y98IX2cYR7YlqWM03wd888rLr7Lsxv5Vw1wF+MGBSE6BySp0G10Ye2D2ds2D2jHfUUiM 6hSMLMATu60wAF2MgZSyFXwhb3btJJsGxIht6NSNughGApEFgUAi8+KXINzdA3mmhU4f IH6jCfakTP/09ktglrIrheV4LHFhIFstv+I2VhDdT96pf/CVxy9N2vfVvG6ejsE+dLE+ 9hoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=J4R47UwD; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m7si1002428otk.73.2020.02.19.02.52.46; Wed, 19 Feb 2020 02:52:58 -0800 (PST) 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=@linaro.org header.s=google header.b=J4R47UwD; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726764AbgBSKwY (ORCPT + 99 others); Wed, 19 Feb 2020 05:52:24 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:44311 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726469AbgBSKwX (ORCPT ); Wed, 19 Feb 2020 05:52:23 -0500 Received: by mail-wr1-f67.google.com with SMTP id m16so27603984wrx.11 for ; Wed, 19 Feb 2020 02:52:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=lt0NY5ib1Jfzy6tElePJc/SbaXVWZpjySCmieUMPpiA=; b=J4R47UwDGmz+YjGbKXDX5CSCOZO416NJh6ZdqrxFKG3dhVEUsE3rOv1EF8B+Y0iK3q bsAwG3EeaVeX+IyXwpE7L/9wnR807IGNztzxmqCG+FpwrRKwiqUCnGtY5lsp9rM3tizK symTQZXecIKJZdkEExDae2REdzOidfh6IJH2KAITdcgOK0E2OT+I/V0FjmI2CZkhmPZk HsWCrOE44uICeo36LlKHQkB26Bm0LnJRpKN41aLb4wxAmzemJ9M55qSaNKWKA2PQ0I8y fgocye9J0gLkdY02OJ8zNS3SBSK/6saMb2e/ypV11YVYGCbhZ9jejZUJWEMsgpX7HbJz eICA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=lt0NY5ib1Jfzy6tElePJc/SbaXVWZpjySCmieUMPpiA=; b=jijFRG8g6CmwZWx8ED1Arfu2prmtvFOJ9wfwhY9JqYI/6K4oGB1xn3u1ZAA2VCQ5WM qXM8+hSDnx+yXOG8o9/YPIE6Mjeg2wUSwJTxUw0WRse0e1f6TplnJS/CFzTCC/ZuQIIB ObR+wF1gVAGHQrSMv+6D7aBw9Q8G8uLXYAvQXgG5rwOpVFvwqV7notg+UeWzo9i4zPQs GanNSZ2FbR4oLIZ8+86LSHBQn8d/VCnTJf0RFJKvf0DiGG2678GsHIzVXrGaL6TmGmDD PA5My1NVt1vwtCTFZO8G50pKTa+ES04l3oDxaleHCN3EBP4+GZY0/bbfHGlcK7FsM80z S2Sw== X-Gm-Message-State: APjAAAVbbBQPVP9PP43p3o35yfJvneT18Z0cyc8ThGx7V11Xn3vSllIp zMLgBA9adxgxuAZ0dk9AXdmxeA== X-Received: by 2002:a5d:5381:: with SMTP id d1mr34595050wrv.259.1582109542207; Wed, 19 Feb 2020 02:52:22 -0800 (PST) Received: from [192.168.86.34] (cpc89974-aztw32-2-0-cust43.18-1.cable.virginm.net. [86.30.250.44]) by smtp.googlemail.com with ESMTPSA id z133sm2623662wmb.7.2020.02.19.02.52.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Feb 2020 02:52:21 -0800 (PST) Subject: Re: [PATCH v3 1/7] nvmem: fix memory leak in error path To: Bartosz Golaszewski , Linus Walleij , Khouloud Touil , Geert Uytterhoeven Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski References: <20200219092218.18143-1-brgl@bgdev.pl> <20200219092218.18143-2-brgl@bgdev.pl> From: Srinivas Kandagatla Message-ID: Date: Wed, 19 Feb 2020 10:52:20 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <20200219092218.18143-2-brgl@bgdev.pl> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 19/02/2020 09:22, Bartosz Golaszewski wrote: > From: Bartosz Golaszewski > > We need to free the ida mapping and nvmem struct if the write-protect > GPIO lookup fails. > > Fixes: 2a127da461a9 ("nvmem: add support for the write-protect pin") > Signed-off-by: Bartosz Golaszewski > --- > drivers/nvmem/core.c | 7 +++++-- > 1 file changed, 5 insertions(+), 2 deletions(-) > > diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c > index ef326f243f36..89974e40d250 100644 > --- a/drivers/nvmem/core.c > +++ b/drivers/nvmem/core.c > @@ -352,8 +352,11 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) > else > nvmem->wp_gpio = gpiod_get_optional(config->dev, "wp", > GPIOD_OUT_HIGH); > - if (IS_ERR(nvmem->wp_gpio)) > - return ERR_CAST(nvmem->wp_gpio); > + if (IS_ERR(nvmem->wp_gpio)) { > + ida_simple_remove(&nvmem_ida, nvmem->id); > + kfree(nvmem); > + return ERR_PTR(rval); Why are you returning rval here? This points return value of ida_simple_get and not the actual error code from wp_gpio. --srini > + }