Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp5084665ybv; Mon, 17 Feb 2020 11:56:33 -0800 (PST) X-Google-Smtp-Source: APXvYqwo5aOMxHAITa4kI/EETQaY4AR87Qht+tIIEnry+1tB+RcG0GDJRihdwD3YOzGv0a4xTi3I X-Received: by 2002:a05:6830:18d4:: with SMTP id v20mr13472525ote.29.1581969393809; Mon, 17 Feb 2020 11:56:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581969393; cv=none; d=google.com; s=arc-20160816; b=thezFhnYx21G7RD2zuIZCy2mFJn1bN75+pm+2U/0YD/OA4LwJqto5AtwXJSsfgmjtH aHOBngjwxWxDMOgtVHDn5Z+wyyBTbIKWhLTzZtXfBThstyBsGwbRD8Yc/zJShycBiFPh Jee3PZgZUq8aUKYR1mgqsvlc36RQaZ/1NAq32LEdBjAxFWbx9u8yIXe82j+YsCYyP4DY 4T8cgVhcPXwxjQbui19jsjezkSqaFIx2F4PPY5FX6ywgiQd2ZTKpvShh3z0c4HyTXWmV 1cu0z+ET4+uJ+FLqzW0lSJGyaV5dF2QOIUiNDBIX089igNGK8lOWVgtBGFvH1MHXoXzf 0LKQ== 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:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=nG7/CsSYEjJAJuvHDKY3X2jyLTeRabTAHO5K7wLe+ss=; b=Wogq+gze4cunGsqWDVh0Pe/jF4SD6eTHxEYz5j9D0Ru3xVlgPNolGVxD6w0UaZfRsc I3ToeSMC2ITeZRkZiHOtB50c/nLia7/AUkSij61l6Wr40mT5GRXzTb+da5FdH5bLGXpf GWIPPq7wyQDoHjbqgQ9VybxtMTzTJp9dbLv1DHIK2Ag2AGTjXv2VGBfgVCrsoox0cD4f u0bTIeBMnKcicmEamsKE4iZhNUc1dMYW9FmD8UATy8s2i3xYly6qJ3GNSC4l0TqzHEjN YA0GgB98cgtKCHm/xk0NcN+MPpfMDgEzfZXpgUqD+Caba0YoNr0ShOVFlNwJzyc2ij8X 7Q3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=Wp87GGdF; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z1si658007otq.21.2020.02.17.11.56.21; Mon, 17 Feb 2020 11:56:33 -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=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=Wp87GGdF; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729800AbgBQTyz (ORCPT + 99 others); Mon, 17 Feb 2020 14:54:55 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:34029 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729716AbgBQTys (ORCPT ); Mon, 17 Feb 2020 14:54:48 -0500 Received: by mail-wr1-f66.google.com with SMTP id n10so19261958wrm.1 for ; Mon, 17 Feb 2020 11:54:47 -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=nG7/CsSYEjJAJuvHDKY3X2jyLTeRabTAHO5K7wLe+ss=; b=Wp87GGdFrmFk3U/BZkSkkgGt/sjUYCkspxOgsVivKDbqdAWSJuc3rEaXm43AIwdpUh 93/5GDxj8IWKuwTuMovC/U8+voqHbS69hKMSu8CWLA0CSi6JoeNJ2YECnBskVhYxIcuY ZKQHYTBWYwuoGihOTyTMlODqMi6EPmIWLgE4JHAosyiowDpZhg5NH6f/vkb65poh/z9u hKL5WylgKaKh07RqdR6+KOAHoEG4fqK7qxMzODPuA8luvcm/YUTmbNdv4/lIs1SHGUB8 xYuDDXwvN5DxbizuG5kcpyNG3m0ZKrI8wgnhhnhK+rvLpiUfoDOzVYsR4InsqRGAFxNU sZyQ== 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=nG7/CsSYEjJAJuvHDKY3X2jyLTeRabTAHO5K7wLe+ss=; b=D/UDudcmU07SxnnS2takbq0HzYkNQSnD7e0yj1DnA0IUb/xky7yORgxeYzRufCvSu4 aMUDtGEEXbj8S3whv17BBAaJBlIB/v0FV3U8LDQTFSOpbAal4PacKiNwYqkF2/w/ZsTU l/BlFIv4EQOALi9rqep//sABqYVOlT81rCTHtED3QtK1+AWIcDbhLnLehkl+VBKeCCrf cj1GFnYjnHCIleGBHrEwZDWDchMMTKJAuGysA406OiXgmWJcGPgxMKIEueu4remcqeX+ jVN60O7iNmj1CQVPQyDnTQv2QzCVTYHenhCNw47FHkcDJLxmo62lVs6vLADx/PuQKmAp fQCA== X-Gm-Message-State: APjAAAXojkVlNAt199RDu5REizF10PkxffD9HsUBlrwHTr7deL03BiJT XEkGNI6rDTrRJgKmCnsosoTarA== X-Received: by 2002:a5d:510f:: with SMTP id s15mr23606937wrt.408.1581969287003; Mon, 17 Feb 2020 11:54:47 -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.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Feb 2020 11:54:46 -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 6/6] nvmem: increase the reference count of a gpio passed over config Date: Mon, 17 Feb 2020 20:54:35 +0100 Message-Id: <20200217195435.9309-7-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 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 096c7bae9e74..b7b1e3194453 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -349,11 +349,13 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) return ERR_PTR(rval); } - if (config->wp_gpio) + if (config->wp_gpio) { nvmem->wp_gpio = config->wp_gpio; - else + gpiod_ref(config->wp_gpio); + } else { nvmem->wp_gpio = gpiod_get_optional(config->dev, "wp", GPIOD_OUT_HIGH); + } if (IS_ERR(nvmem->wp_gpio)) goto err_ida_remove; -- 2.25.0