From patchwork Mon Feb 17 19:54:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 207288 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A9F85C34028 for ; Mon, 17 Feb 2020 19:55:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7F29D215A4 for ; Mon, 17 Feb 2020 19:55:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="gs3t2/Ty" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729646AbgBQTyp (ORCPT ); Mon, 17 Feb 2020 14:54:45 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:36240 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727332AbgBQTyn (ORCPT ); Mon, 17 Feb 2020 14:54:43 -0500 Received: by mail-wm1-f66.google.com with SMTP id p17so552030wma.1 for ; Mon, 17 Feb 2020 11:54:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BYR9M1clfYHE1v0ARZeaLz8iyf2HR4xKCefQlA8DsFQ=; b=gs3t2/TyF6gF+0zoSvNHpJqpWvhb+OJTbYK+Rimp36zPn+Um3KJI7jU6an+eaF7C1g 6bsumWdRMHjnuu8oDRtMjAmZNmF/iEZdH8FIQIDkZW0GoN1Ni5mJC/WdxAzKosceidc9 3KClzAWGMg9kM5UDMuCWqhF7Qya3RyFEi9tCZUhzudbH0PYxgQ3+LYPEgQWWA0OT+UrJ m1VtSJwQTkRE3jKrGldEeOzw/QHMImAEvgHNLITBFtM2+0TDCPKaWMdEZYXRfI/sL2nI lN+tYgD7vqesBkEHp6/BgDbCgcnE/c3uLWTbIAheHZ0gGv4fYRQ6leWLrsVe6x72HxBB RkHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BYR9M1clfYHE1v0ARZeaLz8iyf2HR4xKCefQlA8DsFQ=; b=EOxGaDwv7/qtifAPgZbHdJa1tw1N5Hsv51D8IhUh/G5ovjsb3WaaOpoxh+YC5q7Nm2 RL++mMBwhSU6G2o13KspT24+jve3SC27mrvHkDisetfCDC4grmuzz6r7MUvSogrqBIpl iFK7QCcwJyg/13LkLrHyGnob//DG0b2WuMGTHp45efobZYNI7NM1HZJ8PpXCj6opeHb1 UMyfEljgpfYXN2oWtZXPEngpSrhb7pTMGb8MLN3RTfA2dRc8EXJaG+s+3MqgkaRewzQt rhpbKaePlLrG8T+uhu3GWeNm3ld7rxtcBWnFZUSLTwahEuF7+mgfn7AkpSLHlZLoOQYp 991w== X-Gm-Message-State: APjAAAVeB/oURMcJlOU2o+3HN0mbRLkZ991luldKCHNY/gG8l0iN6QQa HCvytHeQ01DBDUQVIIpNx3kQyA== X-Google-Smtp-Source: APXvYqzCRYEvCvyjC143+OuW9Wo/mGyHqbMmxdGTb0RSKx1nDwE2TWGL9MQamtoIoyVcxmyNjrfDjg== X-Received: by 2002:a1c:a553:: with SMTP id o80mr598696wme.94.1581969282023; Mon, 17 Feb 2020 11:54:42 -0800 (PST) Received: from debian-brgl.local (8.165.185.81.rev.sfr.net. [81.185.165.8]) by smtp.gmail.com with ESMTPSA id v5sm2679469wrv.86.2020.02.17.11.54.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Feb 2020 11:54:41 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Srinivas Kandagatla , Khouloud Touil Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 2/6] nvmem: fix memory leak in error path Date: Mon, 17 Feb 2020 20:54:31 +0100 Message-Id: <20200217195435.9309-3-brgl@bgdev.pl> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200217195435.9309-1-brgl@bgdev.pl> References: <20200217195435.9309-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski We need to remove the ida mapping when returning from nvmem_register() with an error. Signed-off-by: Bartosz Golaszewski --- 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; 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); } From patchwork Mon Feb 17 19:54:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 207289 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 551ECC34026 for ; Mon, 17 Feb 2020 19:55:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2FAF120801 for ; Mon, 17 Feb 2020 19:55:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="AfUrW2gb" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729612AbgBQTzJ (ORCPT ); Mon, 17 Feb 2020 14:55:09 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:38921 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729618AbgBQTyp (ORCPT ); Mon, 17 Feb 2020 14:54:45 -0500 Received: by mail-wr1-f68.google.com with SMTP id y11so21192761wrt.6 for ; Mon, 17 Feb 2020 11:54:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ibj9ygukPb9JYTU3mvyTkp2n0e9w9M7BBgYCc3RsiE0=; b=AfUrW2gbRewzH09iwIz4mOgbGI6xRBf9V9DBjRYX99k7rC43NLrIJeL6iJOtP29bzB XCOotyERZgjri2cgQbwB4/Xo+gvADjygCIZtn+ulJDnkKEj4NAwMK5r1IX0RYRQSwLve 7kxRgQI6sHIb0PzQ5N8S/BuHDaQ4vkSwMm5wASgU/fuzdt7pY6b52pbEA92AZc/sI+0A mcwUlZB5A/LUknqRjE0c/UFaDX4boKsYsSjzLplgC/LBi17NNk5lWG11u5m0oBrTCoe4 WLUWqiiC1tiNhiMhs3bf0+mvd9Hd6ZQemDM8+sGDb5uKBs9miGLRl065Hzb1zNdfuAIY XrwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ibj9ygukPb9JYTU3mvyTkp2n0e9w9M7BBgYCc3RsiE0=; b=Xt7SG4l4I/iykWupaQDS/48xnOtvAWjHYjZd3UQGw2zZ2pMSnngHPe/Fmo4DIxlFZp 4BZGl93GZNxnd+0+oZ9oRVTRqi+HfrNtTv+nZAkEyKA4IMIWqbkk1O+FenFmCqwNnNMe /KoJkZ+HgGn3c/96H7Gi2DsiHa5609TUjJWFx2QSFroxuylLO/8ugZS/Hr48zwbrrqmx IvFw/0JSePZu/bgzyFPSXP1Vs8GDsE+VyCMfCVuYaQAfyE7HagVA8D+jKEK9oVjlSpbO T9iWMwzNsLfSbz967qWy90EM2kfbrx6qiL7igg0zQRqEjJ3hKv+FDjPrjZcDv5NSn30E /2fA== X-Gm-Message-State: APjAAAUzY2EppXGc5gwKQas8qd1xyz6Unrk8kUyLNGjDEgRavaSMTpoU KL1kTn2tuv6ERQPioNXdY+Xh/A== X-Google-Smtp-Source: APXvYqwlWIo4hBNxAnsgARfbUQqYYsyWocS3dL48hvcsR9M5AfzTmKuPqXmaiVFdJ0j+MGV16uBXqg== X-Received: by 2002:adf:93c1:: with SMTP id 59mr24275455wrp.399.1581969284441; Mon, 17 Feb 2020 11:54:44 -0800 (PST) Received: from debian-brgl.local (8.165.185.81.rev.sfr.net. [81.185.165.8]) by smtp.gmail.com with ESMTPSA id v5sm2679469wrv.86.2020.02.17.11.54.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Feb 2020 11:54:43 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Srinivas Kandagatla , Khouloud Touil Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 4/6] nvmem: add a newline for readability Date: Mon, 17 Feb 2020 20:54:33 +0100 Message-Id: <20200217195435.9309-5-brgl@bgdev.pl> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200217195435.9309-1-brgl@bgdev.pl> References: <20200217195435.9309-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski Visibly separate the GPIO request from the previous operation in the code with a newline. Signed-off-by: Bartosz Golaszewski --- drivers/nvmem/core.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 12e2991cdeef..07af9edea9cf 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -347,6 +347,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) kfree(nvmem); return ERR_PTR(rval); } + if (config->wp_gpio) nvmem->wp_gpio = config->wp_gpio; else From patchwork Mon Feb 17 19:54:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 207290 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E5025C34028 for ; Mon, 17 Feb 2020 19:54:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BC5EB206E2 for ; Mon, 17 Feb 2020 19:54:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="C4pRCrEH" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729717AbgBQTyt (ORCPT ); Mon, 17 Feb 2020 14:54:49 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:34026 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729698AbgBQTyr (ORCPT ); Mon, 17 Feb 2020 14:54:47 -0500 Received: by mail-wr1-f66.google.com with SMTP id n10so19261918wrm.1 for ; Mon, 17 Feb 2020 11:54:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=eHHf1AZ6awg6rJEgh/8j8fVolWpvz1BWWO6jH4U66VQ=; b=C4pRCrEHMcQUiX8lZV0P4XL69BR8YUU9PP6rWhgtMHuCoWh/myi3b5qfmjy9WocIpy DHXBPE8EkUFoOzl9PF+6uf2tZwZGfXt2V+zbIxPIu22QBXucp7J94F+E/Sqg8h7eFSMn oQcwixYdX5y01EO75gA+W7p+/slUA7SGbkYZdkvQR87JLbK6Ryiuvj4bWMojUz8wKoy1 rtL6f/xWlzAcPDAbbDh3V9S9udsvuiHLrmP67RLX+JSdFrX0XrkNN0caJY1jLFMH2oKd ek1MynhYu75OejfO1p8clQEfwu48CBL+4xHOiEgQrkgq9sb2JqloRuzL4+ZTVchmKoxs bRKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=eHHf1AZ6awg6rJEgh/8j8fVolWpvz1BWWO6jH4U66VQ=; b=d/FCk6nh9IVzFI+0i6XELhnKcwBwE5czRfZ27Wv0lE+jgx896lsR1y6LUBB7Z6WiBM TcECpMqxAI8kCWW0es0b6JMrX1mIBfAniDYJ5OmhBF0KAc+4Z7b+yIHIsqnhAH3TutHe UQgwupCNev3J8PKa+Fun1zmPEFeEqLeWnrEdxux8Vm8p0kazITdehusqjUFPAdpL6Lrm m6tsE4RVjUJUU2tpvp9bBnLqqZNq/igzywgT4ZP2DrQvW/xu8tn2QwoZksXLPnxebc2w FEQw+wauhRCLEe2aeB/Bvnws3dPrkJ/aqwJ/1i0ckiP/xB+07i3uxEf3jlqEppno4C9L ILCg== X-Gm-Message-State: APjAAAU9yOK4qi9fa+pANTqcGkEAE9o5oGSMYcS/Poi65k7jUv+4yM50 1Ltc3zxzXpWUHUfmmrq9wZ+cA4KINW0= X-Google-Smtp-Source: APXvYqycds3+uTkCmmj1bwhdP3qSWBf6e5zvFgV9quta8k08gJuuEtpvCJRiNDNb8sCWbK7ForeUcA== X-Received: by 2002:adf:f3d1:: with SMTP id g17mr22826005wrp.378.1581969285841; Mon, 17 Feb 2020 11:54:45 -0800 (PST) Received: from debian-brgl.local (8.165.185.81.rev.sfr.net. [81.185.165.8]) by smtp.gmail.com with ESMTPSA id v5sm2679469wrv.86.2020.02.17.11.54.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Feb 2020 11:54:45 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Srinivas Kandagatla , Khouloud Touil Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, geert@linux-m68k.org, Bartosz Golaszewski Subject: [PATCH 5/6] nvmem: release the write-protect pin Date: Mon, 17 Feb 2020 20:54:34 +0100 Message-Id: <20200217195435.9309-6-brgl@bgdev.pl> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200217195435.9309-1-brgl@bgdev.pl> References: <20200217195435.9309-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Khouloud Touil Put the write-protect GPIO descriptor in nvmem_release() and in the error path in nvmem_register(). Fixes: 2a127da461a9 ("nvmem: add support for the write-protect pin") Reported-by: geert@linux-m68k.org Signed-off-by: Khouloud Touil [Bartosz: - also put the gpio in error path in nvmem_register(), - tweak the commit message: the GPIO is not auto-released] Signed-off-by: Bartosz Golaszewski --- drivers/nvmem/core.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 07af9edea9cf..096c7bae9e74 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -72,6 +72,7 @@ static void nvmem_release(struct device *dev) struct nvmem_device *nvmem = to_nvmem_device(dev); ida_simple_remove(&nvmem_ida, nvmem->id); + gpiod_put(nvmem->wp_gpio); kfree(nvmem); } @@ -430,6 +431,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) device_del(&nvmem->dev); err_put_device: put_device(&nvmem->dev); + gpiod_put(nvmem->wp_gpio); err_ida_remove: ida_simple_remove(&nvmem_ida, nvmem->id);