Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp5671226ybv; Tue, 18 Feb 2020 01:42:56 -0800 (PST) X-Google-Smtp-Source: APXvYqw6b6W9FgoB09zjShZmGjt1mXJdNxT7cA+NejzVhK/+ILnBCTkehTKIRR+QganrJde2TceB X-Received: by 2002:a9d:2dea:: with SMTP id g97mr15270506otb.33.1582018976179; Tue, 18 Feb 2020 01:42:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582018976; cv=none; d=google.com; s=arc-20160816; b=ijGPgVNJi9ZuZxTnS67Y40sBsQPUCEnzA0eirgjS/O19OQudt2TzAPe/yG4xPh7m8A ucwrUV8tHRuf6uoB9ob+k+rhDva3QYdvZW4BRUH/uThG3AXUULDlFk2MDarU/YvXMcSU BpMu0UL//rYjEp/U+K48vq2u0MFDIzCFcEyiRC5WBPOnjZ3JvHjE49aPVXppiE2TKCRs d3lVqcCmMmYwcA8OlByvqz756NTSbrm/MVk3K16jxhTVEi+LpW176ezrAH5a1FvOYUmB t6Lj+9kI2/fpj+oAmnhUr/Zm3LhyHEgw4LMM7U7+jomV10UzP+KRJrRcOMhiy1N29FUP wwxQ== 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=iSpUEW7beHak9UFrM6ih/G70K0ztc6Y3OmsEa5YMS5I=; b=dNV67Q+BMrSYf5hVa4n980mPfQWDErkRoR47B9CZpaF37Up6acI/YObMzA63eU1BCt L4hqvwnP4TMo6opx6Qr5pTuOC9Yi8+vTzzXi9L4/fYUCvFkxTlORwveyaroAUJVtGvsU D8ScQ8v4j8tRBWB5AOPnjxrHAzvB5pCkk6H/gq1WuHs7CQ4RMKInDO+wBD91Bzrkqu1x BQ4QzccaxdRv9iXfBXi5PukVEYEgPUSXv0atW5Z8PnO+fmXBFzasIh7/GZhkuoee+Obv 24+twTR2QiFahiDqIh12Q8cjh1OmsfVo3vtaEEkSMfmkGHEJAn4gxT71kVIfA1c5XK0u i3Ag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AU8BMEdH; 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 v10si375934ote.275.2020.02.18.01.42.44; Tue, 18 Feb 2020 01:42:56 -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=AU8BMEdH; 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 S1726640AbgBRJmJ (ORCPT + 99 others); Tue, 18 Feb 2020 04:42:09 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:38617 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726323AbgBRJmJ (ORCPT ); Tue, 18 Feb 2020 04:42:09 -0500 Received: by mail-wm1-f68.google.com with SMTP id a9so2092651wmj.3 for ; Tue, 18 Feb 2020 01:42:06 -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=iSpUEW7beHak9UFrM6ih/G70K0ztc6Y3OmsEa5YMS5I=; b=AU8BMEdHS2+zOtGQ5oh+Xfc3PTOg7SSXbjXfZNjvQDQEGL28W3Vzys5I6GuBWU+WzU IRIornPAr3QGw9Fs/tV2y1jjC7nXn1lCWsonLmvTw2grML8+9n/KLfvHeJVt3PYFEYVD hv7v4pnz3i6grhRfKP/20gv3cMmQkw4WFElD3Pibh3Wd9mLUhFjKt4JwrIsfMX2LAzkq GiJ9zKeEvg91pVZbaIRA+kHY4LfgQXbCmA02PlIhViCERfDyxc3nLfc37o0+bt28UkR9 WmSNh9UtraWmEHah/zTkR6LkYVuA/Trb8SY4XxRIShbSGdPxRgTcS6UcxuqU91yype3P S1LQ== 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=iSpUEW7beHak9UFrM6ih/G70K0ztc6Y3OmsEa5YMS5I=; b=pBAE3ZowRdbZEhAHO+1bg8dQsMJ/2KJf9d4iz+xN++hKTkGSECkxOyjtCIq/oEEHV+ OYw6Ot0c3qP6pEA0c0tGiMnfMaGE6p5UX5IIZPCHAJ6KS7gUhU1SO68raIS3RX7Kly/7 lAxPa0yVVXHfxES5T9eUZdDtOnUhJ+tjT3mpFxlC8i+wK5SunFl1Uq5cBkGWlO7/T+Q1 mCYSSVeiwO+3kkiwIqQgoLBJ0MTAP3064G6RWkcMhxjPHvw77OsI14aR+s8Rbe9uQ2Nu PtQyvfNE6Ta9FLHOyGbfRjvI0mlQ5ov8jyQooi45v17c7c8R9SE1+bxuR7gc8WYnqPbX tDWw== X-Gm-Message-State: APjAAAXY6b6o2GfA6QZKo/zmOqpB4ezrrD+UhzIKAelE/hKcBZsojIXW UK7Hr/a6E1etnyKduzsde9C/Jg== X-Received: by 2002:a7b:ce18:: with SMTP id m24mr2105877wmc.123.1582018926170; Tue, 18 Feb 2020 01:42:06 -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 y17sm5041589wrs.82.2020.02.18.01.42.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Feb 2020 01:42:05 -0800 (PST) Subject: Re: [PATCH 2/6] nvmem: fix memory leak in error path To: Bartosz Golaszewski , Linus Walleij , Khouloud Touil Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski References: <20200217195435.9309-1-brgl@bgdev.pl> <20200217195435.9309-3-brgl@bgdev.pl> From: Srinivas Kandagatla Message-ID: Date: Tue, 18 Feb 2020 09:42:04 +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: <20200217195435.9309-3-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 17/02/2020 19:54, Bartosz Golaszewski wrote: > From: Bartosz Golaszewski > > We need to remove the ida mapping when returning from nvmem_register() > with an error. > > Signed-off-by: Bartosz Golaszewski Was too quick in my last reply.. > --- > drivers/nvmem/core.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c > index ef326f243f36..b0be03d5f240 100644 > --- a/drivers/nvmem/core.c > +++ b/drivers/nvmem/core.c > @@ -353,7 +353,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) > nvmem->wp_gpio = gpiod_get_optional(config->dev, "wp", > GPIOD_OUT_HIGH); > if (IS_ERR(nvmem->wp_gpio)) > - return ERR_CAST(nvmem->wp_gpio); > + goto err_ida_remove; Looks like this is adding nvmem leak here. May be something like this should help: if (IS_ERR(nvmem->wp_gpio)) { rval = ERR_CAST(nvmem->wp_gpio); ida_simple_remove(&nvmem_ida, nvmem->id); kfree(nvmem); return rval; } --srini > > > kref_init(&nvmem->refcnt); > @@ -430,6 +430,8 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) > device_del(&nvmem->dev); > err_put_device: > put_device(&nvmem->dev); > +err_ida_remove: > + ida_simple_remove(&nvmem_ida, nvmem->id); > > return ERR_PTR(rval); > } >