From patchwork Fri Feb 21 15:48: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: 1242179 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=Qmd6KmmR; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 48PG8h2yQQz9sRk for ; Sat, 22 Feb 2020 02:48:52 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728299AbgBUPsv (ORCPT ); Fri, 21 Feb 2020 10:48:51 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:45460 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728364AbgBUPsu (ORCPT ); Fri, 21 Feb 2020 10:48:50 -0500 Received: by mail-wr1-f66.google.com with SMTP id g3so2562566wrs.12 for ; Fri, 21 Feb 2020 07:48:48 -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=t4BvL1ZlG+iRqlGHWziElUGj9TJcDWR1qYvsM7P0dRI=; b=Qmd6KmmROqKDsZsi7NX//sxRru6kte9rqCs1JCZoZPDg6LrdUwUHtPHDLMoRWV59Nn rWTaSliJhyzXfFw92h1vXLGr9A90J6tWZZrJGcIfFg7jZkfyyXJmp+ZgH6qPP4rR/7nA Ju7+8oJj8vfVqTyizIZLsk9Qq0DF+DZYOeQxB8TDqWpn1QKmXOLJXfO16MnriTDy+URC GqIxWKZeQ2Z2pmNeKOAx4ubkgi1BDEe/7I1KJXbJBeDqo7GXjHoFn6A3QxaaptD8jQp2 n4A9UH0a/wjfilA88zTGpgAoeH/Agjgcpi7QK7BajjMUF7sqsKw43jjW1j+VMAikR8bF 8fVw== 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=t4BvL1ZlG+iRqlGHWziElUGj9TJcDWR1qYvsM7P0dRI=; b=l1bBjDm2DTQVpr+xBMNKgtExK498zEOFM1U8DOsNZrU27I3gSNf1ES5mqg0z4Dj54w rf5rqw9Q5fMSyMkdgvySwF47Af+MpIQwUjTPcfXl2ZKk70mtWqL9RxK7YYrgc2jOtbBb aVhOKlRNNj2tuQzuo1JTekSDK3J4kKA1jTDk44+EdASRpsv09T7uR5ZKOc/C1K/eYWHd PXFPfuJK2zVer33ce34Z9aSTblCE3yklWFd3KjRyDfgFw3CLRyevwggKH32zfLBgtwDi oZ1GXlUvS7HxSCt5w1PWwhvV0HFMzTzbi5TUbLm7qsCfoAYcJt04UTWXXLss5eTo5nY6 fFWg== X-Gm-Message-State: APjAAAXwQ1KOAZSRPcGAmpKAQmC+M0VhL6XxpESrgVgEP/wgh/iR6GVv EN1wYIasPBGmqdc5UMflGFdB6w== X-Google-Smtp-Source: APXvYqzIbzesr3Ocn/5qxdLjpW6lcX41+ayfLH8l4XpNrxYb95wmn2ZXDGkHP8Jf0SReVu5RGEHR/g== X-Received: by 2002:adf:f6c8:: with SMTP id y8mr48557796wrp.167.1582300127356; Fri, 21 Feb 2020 07:48:47 -0800 (PST) Received: from localhost.localdomain (lfbn-nic-1-65-232.w2-15.abo.wanadoo.fr. [2.15.156.232]) by smtp.gmail.com with ESMTPSA id h10sm4267947wml.18.2020.02.21.07.48.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2020 07:48:46 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Srinivas Kandagatla , Khouloud Touil , Geert Uytterhoeven Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v5 1/5] nvmem: fix memory leak in error path Date: Fri, 21 Feb 2020 16:48:33 +0100 Message-Id: <20200221154837.18845-2-brgl@bgdev.pl> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200221154837.18845-1-brgl@bgdev.pl> References: <20200221154837.18845-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 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 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 503da67dde06..2758d90d63b7 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -353,8 +353,12 @@ 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); + rval = PTR_ERR(nvmem->wp_gpio); + kfree(nvmem); + return ERR_PTR(rval); + } kref_init(&nvmem->refcnt); INIT_LIST_HEAD(&nvmem->cells); From patchwork Fri Feb 21 15:48: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: 1242180 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=RI1Eye7X; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 48PG8m32FKz9sP7 for ; Sat, 22 Feb 2020 02:48:56 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729263AbgBUPsz (ORCPT ); Fri, 21 Feb 2020 10:48:55 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:51978 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729169AbgBUPsu (ORCPT ); Fri, 21 Feb 2020 10:48:50 -0500 Received: by mail-wm1-f65.google.com with SMTP id t23so2276332wmi.1 for ; Fri, 21 Feb 2020 07:48:49 -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=Kc3RH6cl8PrURMVC2HcOMEqzVbKCqch6ndQPKF/V66A=; b=RI1Eye7XDj1Sf4dEbOo6SKh+OtOPT62d9EGBP15dioK9//v/oxEheCrG4DZXrkVurJ VEU03SSY5RtDayC9Ly5GNiz1jPKY8k7sxHYdSIOzdX6lnBGm1HBtvLxdaqnJSz5MtGvB Bxg1LmCfvHxMb+Ux9j6QNOK7//ktcTYB3yHsnONKRDiNj3hKYEHh4TyZYJmJ6StVvCDb K3n+8GRLuWsP+tacCC4LVSnIg+Sy6ENIjVWC3xF4UEIuFu1cEOsj7A+HxoHe0CSrJroR 4mBHsP/ElDeMemZ10+r2VeAYr+5PcEoDnwO8CDjZL6XEfodYS2VWeDXPfYD43k9Ry8Dg 6qnA== 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=Kc3RH6cl8PrURMVC2HcOMEqzVbKCqch6ndQPKF/V66A=; b=lnD/HYxSmzF0uy8e2BeC/QGrhOeSreB1cVc1We1RVawo1vPUHIISBRLV3zohrBeegx wmrsWPbWkC0BGOZTnf1GEE/EoSHHLqTEo1Br9KwQlfsQUjp6xX0JVfglw7IHKHDdQ4dm GopinHdIfHuTeXKnINKH/SmOKhlrpdcFMVrACtB2tZ9VZgw0fwpCLxhjRkH6S0QPBwEY 93fDxH/H5LgbyWiPl5mSydIJTui3KUK12QjxIGLwf5yiNfbaCopc8Uzp/xCEWJD9TtiL jX2yQSsw0+Ldlx94Hb1Kc+elN+vfd7NsHBxkX/K9iMmyDRbZHmYo0e0CIriK2eVh91Ai cNGA== X-Gm-Message-State: APjAAAUl7Pic6xlFsYJzdxdiStjElITAUo/mJhshZPNBZILVTpQua066 HYIDnvsfWziLBKE1RNM9VY6qRQ== X-Google-Smtp-Source: APXvYqwm5JScae4Vtb7EJK4NqO1U0EeoMiI7GvTzMu19s3xt71xFidsN/+ghrTO1Ugo/ZubaVCEiZw== X-Received: by 2002:a7b:c119:: with SMTP id w25mr4640116wmi.116.1582300129076; Fri, 21 Feb 2020 07:48:49 -0800 (PST) Received: from localhost.localdomain (lfbn-nic-1-65-232.w2-15.abo.wanadoo.fr. [2.15.156.232]) by smtp.gmail.com with ESMTPSA id h10sm4267947wml.18.2020.02.21.07.48.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2020 07:48:48 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Srinivas Kandagatla , Khouloud Touil , Geert Uytterhoeven Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v5 2/5] gpiolib: provide VALIDATE_DESC_PTR() macro Date: Fri, 21 Feb 2020 16:48:34 +0100 Message-Id: <20200221154837.18845-3-brgl@bgdev.pl> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200221154837.18845-1-brgl@bgdev.pl> References: <20200221154837.18845-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're about to add a public GPIO function that takes a descriptor as argument and returns a pointer. Add a corresponding macro wrapping the validate_desc() function that returns an ERR_PTR() on error. Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 4d0106ceeba7..da8ffd40aa97 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -2864,6 +2864,14 @@ static int validate_desc(const struct gpio_desc *desc, const char *func) return; \ } while (0) +#define VALIDATE_DESC_PTR(desc) do { \ + int __valid = validate_desc(desc, __func__); \ + if (__valid < 0) \ + return ERR_PTR(__valid); \ + if (__valid == 0) \ + return NULL; \ + } while (0) + int gpiod_request(struct gpio_desc *desc, const char *label) { int ret = -EPROBE_DEFER; From patchwork Fri Feb 21 15:48:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1242183 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=e06/jlR3; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 48PG925Bg1z9sSJ for ; Sat, 22 Feb 2020 02:49:10 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729253AbgBUPtJ (ORCPT ); Fri, 21 Feb 2020 10:49:09 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:36179 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729224AbgBUPsz (ORCPT ); Fri, 21 Feb 2020 10:48:55 -0500 Received: by mail-wm1-f66.google.com with SMTP id p17so2412969wma.1 for ; Fri, 21 Feb 2020 07:48:52 -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=zNOyXL2FHV1G3B3dMKi0NeHmPme3SyjuhzWOnvysfO4=; b=e06/jlR3Xwj0soL+EDf9/Gy1sjopUiSvXC+XtqUVPQxBvCHkODs3Zx4PnV9t3MH4JU l+OBb2kcjOFLo39kJ0XPZcUROuyKYAURuoBljL4yoq4DTSfGwrhZOry2Fm9KyKeZk1jE dCsO+2Qio9iv7eEJbwlEmwbFCY5jZyVL+oM10PXEtwFahGCIz1EH5sMbDhEgwpkozxaS AHH5p3ZWjEkqq21eO/yRjwBd5BUET6p0K3MwqtFRbrZN3TClWi9Fqj++Qscy0ZmaH8Z2 3jn5PC5zIBgfDsGIvmS87aC2FoBXXEGQGNKfNm+lJS7iwvWnC4yIuFcviyuBHhhdjevZ 6M4w== 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=zNOyXL2FHV1G3B3dMKi0NeHmPme3SyjuhzWOnvysfO4=; b=T99xRzG097H2NwUvt6YQQusUCzR/JcuG09ATAUnCnruYiXDFIfR9BnWhyNdSSs0TJW CoLoUxBZMYfPFEKDz0qeN1g7RVJYOC2+JcIvnjgLXdLYX8teKntg0fj8tN3dSZTf35fX xE0m4CVQi5kaKIGz/Ea62gyv2F3QNmLsGX5iKS1SzYTKFW6GKRXuxUXmitlD0lpsTzYZ Ih/I0HHlvkgMO7MWCAhFVjLAHts+z7z1O8UYOkZCy6jwLp702Twe80hNe5lE32y6ATfN yyVHEpDRCY2D7xCs3JDK8JmU5YBf3EBIYJWDrCKv58KI1/0rLe3cpQRes8uFc4AsPyno wX/Q== X-Gm-Message-State: APjAAAWnEmi8BdyJLbx0ece3ei+wy6+3AfCvl78YJddyf1USCwoWsPFy yDQMjnhe7m0jdFfyqGrw5ff4ew== X-Google-Smtp-Source: APXvYqyEtSzwy7SeYEJm34vV+VbjKSo7cTIGWkkhLtuA0xig9qkgHnOUHAAWlL3ybLVc5GPl8Pk58w== X-Received: by 2002:a1c:dfd6:: with SMTP id w205mr4641601wmg.151.1582300131453; Fri, 21 Feb 2020 07:48:51 -0800 (PST) Received: from localhost.localdomain (lfbn-nic-1-65-232.w2-15.abo.wanadoo.fr. [2.15.156.232]) by smtp.gmail.com with ESMTPSA id h10sm4267947wml.18.2020.02.21.07.48.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2020 07:48:50 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Srinivas Kandagatla , Khouloud Touil , Geert Uytterhoeven Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v5 3/5] gpiolib: use kref in gpio_desc Date: Fri, 21 Feb 2020 16:48:35 +0100 Message-Id: <20200221154837.18845-4-brgl@bgdev.pl> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200221154837.18845-1-brgl@bgdev.pl> References: <20200221154837.18845-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 GPIO descriptors are freed by consumers using gpiod_put(). The name of this function suggests some reference counting is going on but it's not true. Use kref to actually introduce reference counting for gpio_desc objects. Add a corresponding gpiod_get() helper for increasing the reference count. This doesn't change anything for already existing (correct) drivers but allows us to keep track of GPIO descs used by multiple users. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpiolib.c | 38 +++++++++++++++++++++++++++++++---- drivers/gpio/gpiolib.h | 1 + include/linux/gpio/consumer.h | 1 + 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index da8ffd40aa97..a00e28ca8a49 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -2798,6 +2798,8 @@ static int gpiod_request_commit(struct gpio_desc *desc, const char *label) goto done; } + kref_init(&desc->ref); + if (chip->request) { /* chip->request may sleep */ spin_unlock_irqrestore(&gpio_lock, flags); @@ -2941,6 +2943,13 @@ void gpiod_free(struct gpio_desc *desc) } } +static void gpiod_free_kref(struct kref *ref) +{ + struct gpio_desc *desc = container_of(ref, struct gpio_desc, ref); + + gpiod_free(desc); +} + /** * gpiochip_is_requested - return string iff signal was requested * @chip: controller managing the signal @@ -5075,18 +5084,39 @@ struct gpio_descs *__must_check gpiod_get_array_optional(struct device *dev, EXPORT_SYMBOL_GPL(gpiod_get_array_optional); /** - * gpiod_put - dispose of a GPIO descriptor - * @desc: GPIO descriptor to dispose of + * gpiod_put - decrease the reference count of a GPIO descriptor + * @desc: GPIO descriptor to unref * * No descriptor can be used after gpiod_put() has been called on it. */ void gpiod_put(struct gpio_desc *desc) { - if (desc) - gpiod_free(desc); + VALIDATE_DESC_VOID(desc); + + kref_put(&desc->ref, gpiod_free_kref); } EXPORT_SYMBOL_GPL(gpiod_put); +/** + * gpiod_ref - increase the reference count of a GPIO descriptor + * @desc: GPIO descriptor to reference + * + * Returns the same gpio_desc after increasing the reference count. + */ +struct gpio_desc *gpiod_ref(struct gpio_desc *desc) +{ + VALIDATE_DESC_PTR(desc); + + if (!test_bit(FLAG_REQUESTED, &desc->flags)) { + pr_warn("gpiolib: unable to increase the reference count of unrequested GPIO descriptor\n"); + return desc; + } + + kref_get(&desc->ref); + return desc; +} +EXPORT_SYMBOL_GPL(gpiod_ref); + /** * gpiod_put_array - dispose of multiple GPIO descriptors * @descs: struct gpio_descs containing an array of descriptors diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h index 3e0aab2945d8..51a92c43dd55 100644 --- a/drivers/gpio/gpiolib.h +++ b/drivers/gpio/gpiolib.h @@ -119,6 +119,7 @@ struct gpio_desc { const char *label; /* Name of the GPIO */ const char *name; + struct kref ref; }; int gpiod_request(struct gpio_desc *desc, const char *label); diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h index bf2d017dd7b7..c7b5fb3d9d64 100644 --- a/include/linux/gpio/consumer.h +++ b/include/linux/gpio/consumer.h @@ -81,6 +81,7 @@ struct gpio_descs *__must_check gpiod_get_array(struct device *dev, struct gpio_descs *__must_check gpiod_get_array_optional(struct device *dev, const char *con_id, enum gpiod_flags flags); +struct gpio_desc *gpiod_ref(struct gpio_desc *desc); void gpiod_put(struct gpio_desc *desc); void gpiod_put_array(struct gpio_descs *descs); From patchwork Fri Feb 21 15:48:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1242182 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=Y3lDq82o; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 48PG920htPz9sS3 for ; Sat, 22 Feb 2020 02:49:10 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728487AbgBUPsz (ORCPT ); Fri, 21 Feb 2020 10:48:55 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:54261 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729217AbgBUPsy (ORCPT ); Fri, 21 Feb 2020 10:48:54 -0500 Received: by mail-wm1-f68.google.com with SMTP id s10so2273259wmh.3 for ; Fri, 21 Feb 2020 07:48:53 -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=vKMOxyJCt3REeokpewoFxr3MprF3IwK5sef8rIuxxMQ=; b=Y3lDq82otxFk1dqt1cCgRQ641wPz1qeZ6rtNOzeXPPi1P+MMOApvLh2jT/xp5t1Toj LtwRWOBZ91kldJcLeIqjFwAJD4oiMfh/L2qR5mR0Qk3yde0F7krR6PGl+9NYmzmfsW1M r1YgcVbob6eXGRs4jzn89WTOl0ZUoj4IsWKFFc+/S43BuPdn+QXPHaezhxFFCzj74GEB f+WcuH1RQoP959hR99K+WKUxgUexYFrZQDm2OwbqFRJEQQUuu7oh2KrMXKgIDpWea57N 54qE/YozafBvJxOLrvPYAqwhOL+bSDozuoo1DcX10Au46MlKlRDp9+dGQZ+6ngQLcRiK ZGwQ== 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=vKMOxyJCt3REeokpewoFxr3MprF3IwK5sef8rIuxxMQ=; b=iC9IylV2qQSfkXfbLl8vYJ2aRZIYQfmWKg6I8a+LeLRG2hCdKYG/8Id8djedYAqLAV nuyDvnou1aBRCENe8ZyPOgH3iKIrhNbd7YYzDCOPitPaHBsIEKg1abSomYLx/gCOTJm4 HHJ+Qn8M+VvR2m4AolaRSXPzDFMvngBDhGNoFpS4o1osqs6b6xbKAO6WC4fkmXOIqKZz ojLOukUQs/LK5FKplt4G6Xz7LT8hF8Ewf9RcXts/kXDqDeaMclsXqRjCZ/Etzx4z/ej5 fojJ9LqNen3EQNIxVydGM6UuvGq+t3PTKqT+Hti6b+htkoSNXkBEXdm4czxAGfeO6LLh 3kuQ== X-Gm-Message-State: APjAAAVdDFWI5OygbSqgtfOuWPO8oXkR3lsElbgD3AuT/N1mfKCWrJgB tIGKa96HQej4ab3k1FmvOa/4EA== X-Google-Smtp-Source: APXvYqygWqoO4iocVUnQ7IG/n/AV4BRCEYimoh/V9meXwbtdzSH072KLZAihSncKmBgLc0oh+YrICg== X-Received: by 2002:a1c:a1c3:: with SMTP id k186mr4502548wme.179.1582300132694; Fri, 21 Feb 2020 07:48:52 -0800 (PST) Received: from localhost.localdomain (lfbn-nic-1-65-232.w2-15.abo.wanadoo.fr. [2.15.156.232]) by smtp.gmail.com with ESMTPSA id h10sm4267947wml.18.2020.02.21.07.48.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2020 07:48:52 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Srinivas Kandagatla , Khouloud Touil , Geert Uytterhoeven Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v5 4/5] nvmem: increase the reference count of a gpio passed over config Date: Fri, 21 Feb 2020 16:48:36 +0100 Message-Id: <20200221154837.18845-5-brgl@bgdev.pl> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200221154837.18845-1-brgl@bgdev.pl> References: <20200221154837.18845-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 can obtain the write-protect GPIO in nvmem_register() by requesting it ourselves or by storing the gpio_desc passed in nvmem_config. In the latter case we need to increase the reference count so that it gets freed correctly. Signed-off-by: Bartosz Golaszewski --- drivers/nvmem/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 2758d90d63b7..4a4ef2049022 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -349,7 +349,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) } if (config->wp_gpio) - nvmem->wp_gpio = config->wp_gpio; + nvmem->wp_gpio = gpiod_ref(config->wp_gpio); else nvmem->wp_gpio = gpiod_get_optional(config->dev, "wp", GPIOD_OUT_HIGH); From patchwork Fri Feb 21 15:48:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1242181 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=pDPNgmdO; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 48PG8q2vc0z9sP7 for ; Sat, 22 Feb 2020 02:48:59 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729305AbgBUPs5 (ORCPT ); Fri, 21 Feb 2020 10:48:57 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:36187 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729267AbgBUPs4 (ORCPT ); Fri, 21 Feb 2020 10:48:56 -0500 Received: by mail-wm1-f68.google.com with SMTP id p17so2413109wma.1 for ; Fri, 21 Feb 2020 07:48:54 -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=weuvYYix3RqIGgN/zRk1CorKOjlasqkVrieHVbtyLfQ=; b=pDPNgmdOf/U0uJA/dCUvRKyjmPqgQvuJPLGrWl10qYMA1x29exMf1l4sMCoM/uyRq3 HW+5fymFWoWTnZ6Ipuwh119yotiA8G/fYUEzHjW2lZT/0/W8DD5VlOpQNw7I2jBIJLzO zGlZqnauVbfzXjoB453dr1XEsE3UdK7Z8lOAjNxhu5asdDQmJXAdfTzhXozAWlBs80B/ juK+HqFYs2X3k/XqQsoCxV7v24sstOWillOR3fN0ESUYNfSUohFjodwZzddws9LqGupi KilmL3Wp7U2udJH8sEleyox/chdfTl2xWR78NHWjZHYV1MpiUMIWaQflO4I66iDXet+G UNLg== 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=weuvYYix3RqIGgN/zRk1CorKOjlasqkVrieHVbtyLfQ=; b=G93I3rqTqFSnfnNpyWwXHK/CKA+vGwYVmccaXkYbM7SScWzMxWCOoZTyVQ18cV6h9X iromIpJ5z36/aWDRC+jh4upcOvZuxn1Jgv5a4gu3ZNEYX+lIO8yicE2iDexhH5GKC31V jLOkkwoUnwKvPYTeMIjNgCsJg8kGD7lCGov6neiHqwZsiInWKIi5G24EePBRunV73Vs0 UwaNr552X8hKyUun0sgBHTdie8SpYlkl/Zv8cwyHomOZZbfY9vmp6z0O5CE8L+N7LUEu kxdWr2hLubpEc4TY0V6O///w6Sdtjx/V9JPZuQCauena7X7C+nNl4PegHoDYnP3OJYi0 xU8g== X-Gm-Message-State: APjAAAVqH5tB1qBYJOEUX7zOmj7GDCD9oyuwPpsFFwZuAORbXUESNo41 9Sg1ucZJrGkSs0j//1/ar/qXsmehqsE= X-Google-Smtp-Source: APXvYqz92SmB6gKyEyIcN3ICAdhIl2aQg8oaEDyPWAMvK1vUcPAjc3XIajuwdwWuLn4EzJh5mbCYdA== X-Received: by 2002:a1c:bc08:: with SMTP id m8mr4707440wmf.189.1582300134092; Fri, 21 Feb 2020 07:48:54 -0800 (PST) Received: from localhost.localdomain (lfbn-nic-1-65-232.w2-15.abo.wanadoo.fr. [2.15.156.232]) by smtp.gmail.com with ESMTPSA id h10sm4267947wml.18.2020.02.21.07.48.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2020 07:48:53 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Srinivas Kandagatla , Khouloud Touil , Geert Uytterhoeven Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v5 5/5] nvmem: release the write-protect pin Date: Fri, 21 Feb 2020 16:48:37 +0100 Message-Id: <20200221154837.18845-6-brgl@bgdev.pl> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200221154837.18845-1-brgl@bgdev.pl> References: <20200221154837.18845-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() so that it can be automatically released when the associated device's reference count drops to 0. Fixes: 2a127da461a9 ("nvmem: add support for the write-protect pin") Reported-by: Geert Uytterhoeven Signed-off-by: Khouloud Touil [Bartosz: tweak the commit message] 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 4a4ef2049022..790ec9b5552e 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); }