Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp4821274ybv; Mon, 17 Feb 2020 06:36:10 -0800 (PST) X-Google-Smtp-Source: APXvYqwXI/8qDRL6u8+Kj7CFTrFiqbGWSbNGFQLBXphoyS3isWQtF3zfk5RL+4pkj+2KrYwQapJz X-Received: by 2002:a05:6808:a9c:: with SMTP id q28mr10446236oij.176.1581950170286; Mon, 17 Feb 2020 06:36:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581950170; cv=none; d=google.com; s=arc-20160816; b=wmyLz2tHLiTjymRppz1yYJCkQCpt6XvRW6WpwFIFPykIduIRFWfuyc2svrQxqS+mBQ dA0rL7mhkMzxFSMcy68kUcCvdiByD4sbz3d67oNKb5SryJRe7C2E6GNufDWwHpyR8WBx DSls8GodDJ2w0jd47W4HTlA0u6r068tA5UKnojAZb4C3asDeG5U7t3LzRN7cdIxZ7svD Gz2p6MLNDJX5gdG+VgDYcE2xLQ54s+nUONfED+Vu6YHQaevuueDzh2fm8befATfFrK1m /QSg2aSrtdKt+IPOwZc+vGOrrnsibo8GEvniKvbqz14jJcnR7hy5Hw5yNa5ec/te0uex 5qWw== 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:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=sYSA9gH5D5QpjxpnnA/foVNSE8oIoSs3/0w1wFARKFA=; b=VhuoHSqRNqLJOSZ2bUW5+YYpfyNkll8kVRTOCGW02zoB0meEqVIsfo6DxWwJeIo1wh 8OnSaQeEWGsZAdyA8pvaDJ2OEAXh2O0erMsLiS02DPOXrbH8uepT7sKl9OMmk05du9jL KQHLUT+4R24kFgUcgIhTDyIhv2GmgVTA2Bgq7pG5M8+Hf4660dQtpNWj8SWHDrTC1Rtm SxI8rkO7YHjb/h3dcwO4ad0KRDFQQKvDqwcDFh0AvuVdEX4f7qKAnLvU3XF9mlvrw325 EpGC9qurIevQP0VUe7dy+VVmXEDWqAXymSrp9K82Puy745wHQKMCLKfv/OExbzFXjBaH ZtdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=WRDJvcS8; 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 i8si6621964oih.206.2020.02.17.06.35.56; Mon, 17 Feb 2020 06:36:10 -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=WRDJvcS8; 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 S1728681AbgBQOeq (ORCPT + 99 others); Mon, 17 Feb 2020 09:34:46 -0500 Received: from mail-il1-f193.google.com ([209.85.166.193]:45518 "EHLO mail-il1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726873AbgBQOep (ORCPT ); Mon, 17 Feb 2020 09:34:45 -0500 Received: by mail-il1-f193.google.com with SMTP id p8so14396739iln.12 for ; Mon, 17 Feb 2020 06:34:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=sYSA9gH5D5QpjxpnnA/foVNSE8oIoSs3/0w1wFARKFA=; b=WRDJvcS8ymr5ylA0UtB/67GmGZlM/1gESH2KXwDfgkuE/OV3VvkijsWD//rIjkTp+/ 3hqMXipaSN4FEmKuuj8U9V8yMz6PPmOmpjeCQeNX5UlPNQw48w7DBB32NR4fuMQIaR58 yLrsthNgb1+PE/pnm3Re2Un53IWzQ/T8cZv5A8Ui84o2GB34SysBLLOfKn0OY+pW80PU WL8chP1WdNh35DgAPQrvBWSN3dNuk5A8WqAZCvKvZ8z0tpWa+OlfblDJHCDC0KcXZ5Tr 6cDyMcg+IoFSILBmpeqABcqwPqv/M4fzd9Y2+PT6Ek9gnQBZX0iMVQh5f4dTxL2Fu2kT MXZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=sYSA9gH5D5QpjxpnnA/foVNSE8oIoSs3/0w1wFARKFA=; b=ScZ8hMFmYa9hwI3BInYQau28P6Ml7xg5PU+NLj7qOLaAk/m0ORPyhEIhOn3nfKZR7X etvHvcmmEZvU9bfrmaK/cfbRYTUjqFSaefrI+DOUMZwKLB70b4HvrgAB5WrHsg/+nO0B PH0Z/iVhWfE9ihmSzZyhiTkdMVuNizul7iNQw3zAOmHflZZ7BURNf69gPsD6CJyfCf20 NdRcR6U2kJg6/s6+F4MQHG2BhA5ct4pYYcWa68PxXUMzUBf1qLv3HCffes36Zuf9v1ti N4uiqrBCXwlxcJzPFNztot1WVAH6Q3Ad+52jBXlojUgmHNYuUVMZbV0nrWGxE362+e3B Zv/w== X-Gm-Message-State: APjAAAU+uaL4QD34TGmB5OToiX/jcI8KDXas0HzRijRxXXPhoqpeY2o4 AmM/hMzRhQFcAgSf/5C2Do4KWaRevEnfstWe/JXkXQ== X-Received: by 2002:a92:9c1c:: with SMTP id h28mr14256156ili.189.1581950085177; Mon, 17 Feb 2020 06:34:45 -0800 (PST) MIME-Version: 1.0 References: <20200107092922.18408-1-ktouil@baylibre.com> <20200107092922.18408-3-ktouil@baylibre.com> In-Reply-To: From: Bartosz Golaszewski Date: Mon, 17 Feb 2020 15:34:34 +0100 Message-ID: Subject: Re: [PATCH v4 2/5] nvmem: add support for the write-protect pin To: Geert Uytterhoeven Cc: Khouloud Touil , Bartosz Golaszewski , Rob Herring , Mark Rutland , Srinivas Kandagatla , baylibre-upstreaming@groups.io, Linux Kernel Mailing List , "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS" , Linux I2C , Linus Walleij Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org czw., 30 sty 2020 o 09:06 Geert Uytterhoeven napisa= =C5=82(a): > > Hi Khouloud, > > On Tue, Jan 7, 2020 at 10:30 AM Khouloud Touil wrot= e: > > The write-protect pin handling looks like a standard property that > > could benefit other users if available in the core nvmem framework. > > > > Instead of modifying all the memory drivers to check this pin, make > > the NVMEM subsystem check if the write-protect GPIO being passed > > through the nvmem_config or defined in the device tree and pull it > > low whenever writing to the memory. > > > > There was a suggestion for introducing the gpiodesc from pdata, but > > as pdata is already removed it could be replaced by adding it to > > nvmem_config. > > > > Reference: https://lists.96boards.org/pipermail/dev/2018-August/001056.= html > > > > Signed-off-by: Khouloud Touil > > Reviewed-by: Linus Walleij > > Acked-by: Srinivas Kandagatla > > Thanks for your patch! > > > --- a/drivers/nvmem/core.c > > +++ b/drivers/nvmem/core.c > > @@ -15,6 +15,7 @@ > > #include > > #include > > #include > > +#include > > #include > > #include > > #include "nvmem.h" > > @@ -54,8 +55,14 @@ static int nvmem_reg_read(struct nvmem_device *nvmem= , unsigned int offset, > > static int nvmem_reg_write(struct nvmem_device *nvmem, unsigned int of= fset, > > void *val, size_t bytes) > > { > > - if (nvmem->reg_write) > > - return nvmem->reg_write(nvmem->priv, offset, val, bytes= ); > > + int ret; > > + > > + if (nvmem->reg_write) { > > + gpiod_set_value_cansleep(nvmem->wp_gpio, 0); > > + ret =3D nvmem->reg_write(nvmem->priv, offset, val, byte= s); > > + gpiod_set_value_cansleep(nvmem->wp_gpio, 1); > > + return ret; > > + } > > > > return -EINVAL; > > } > > @@ -338,6 +345,14 @@ struct nvmem_device *nvmem_register(const struct n= vmem_config *config) > > kfree(nvmem); > > return ERR_PTR(rval); > > } > > + if (config->wp_gpio) > > + nvmem->wp_gpio =3D config->wp_gpio; > > + else > > + nvmem->wp_gpio =3D gpiod_get_optional(config->dev, "wp"= , > > + GPIOD_OUT_HIGH); > > Shouldn't this GPIO be released in nvmem_release(), by calling gpiod_put(= )? > Hi Geert, Khouloud already sent out a patch but I think it still doesn't fix all the problems. While we should call gpiod_put() for the descs we request - we must not do it for the desc we get over the config structure. Unless... we make descs reference counted with kref and add gpiod_ref() helper. That way we could increase the reference counter in the upper branch of the if and not do it in the lower. Calling gpiod_put() would internally call kref_put(). Does it make sense? I think that a function that's called gpiod_put() but doesn't really use reference counting is misleading anyway. > Once that's implemented, I assume it will be auto-released on registratio= n > failure by the call to put_device()? No, I think this is another leak - why would put_device() lead to freeing any resources? Am I missing something? Bart