Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp4027829ybb; Mon, 23 Mar 2020 12:06:24 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuczsodNpv7vI+W8WsP0VRILD5jCnGQrTDCE+NDTLtwHg5b3+2uyBUHEtkLcPHLfFRys44g X-Received: by 2002:a9d:554c:: with SMTP id h12mr19361190oti.16.1584990384722; Mon, 23 Mar 2020 12:06:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584990384; cv=none; d=google.com; s=arc-20160816; b=hhu8lITHBx7Sad7FNfA8QoYmxTyJeEJCaonURneqd8YCNCkbIf5aP9FbHHAADRSNvq 5VI1WYf0OdX4O6AHZcyYGXsu4peKzSmeIHELJiAqDTWtfL6Hnx4EHVAoHHwokefSfj1x 37TPJwf1beMD4ejU3k0DSQcStKGbkc+hJoAPxE8mFgTmuFeewhJ+bLWyiK0kg27LVAuf 4pUfujDMuIwgUTRkF7K8XEgqmziCRcoKAkaNrC/fChy18efSuU6HNjb2ppD7D9oTNqGV sK50DhQ5dMrFwie0WlZf4dR3C3Em5m/iw2/LzWwn/JxSFO0j6u6fd5j8w5I32R3sN16M tBOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=N/AybWcnk9ULLFskRJljRIIjktQNY6Q4XNdIAUuK25U=; b=jMTTbcjjCTIj9o7jD3mkXqhh9hJ8SGoiNO6kvSkyjLKtNnG1yjSWwGAq572K70Pg7H yxm43mvh7y7BS4upsslnO7oRfzOdljTE0W6Vm9TA0SPTqglHGzsLwxHRrhfDZ0mCW12o r47Cw78uwx2ZtyjVnIiJA9G9fd6C9dgKVOqEj6LBi7IBQWHWlD3vwM+Ap58LKCEScdcq QjjUUi3wmTQiD6gW0Gy6JjK58lVJJhAqgIg6at91oJprkLiOyl4keD/1g2/cQD1+NfGb rvDsjqj2Uqm6DppjiXbA4wm88rh7sMWOalKOn6u6HQz+yHmPYoPmFv0YCDAw4KJRmmuR 481A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="cKi/4lao"; 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 38si8104421otm.189.2020.03.23.12.06.11; Mon, 23 Mar 2020 12:06:24 -0700 (PDT) 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=@kernel.org header.s=default header.b="cKi/4lao"; 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 S1727866AbgCWTFK (ORCPT + 99 others); Mon, 23 Mar 2020 15:05:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:54766 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727218AbgCWTFI (ORCPT ); Mon, 23 Mar 2020 15:05:08 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 931232051A; Mon, 23 Mar 2020 19:05:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1584990308; bh=jdBtV9RPdFT7VwigIuuOLSzGDJeem2g/cmvpoZ/9w/Q=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=cKi/4laoKU1BkfSXlOiMXVtcTuH1DkfScCH4aJA2jnrewbHm9rfu5rw/+aCouSYPE B/KnXoFQ6d0/eo6nkJUQpCDzcytcRCuU6icCy/e5zvacYDiqOo/RjMjUQS0xyz+GLr eD6Kf2PGLnIXrfBGDT8TgLPE1T8ijg844JAmJohE= Date: Mon, 23 Mar 2020 20:05:05 +0100 From: Greg KH To: Srinivas Kandagatla Cc: linux-kernel@vger.kernel.org, Nicholas Johnson Subject: Re: [PATCH 5/5] nvmem: Add support for write-only instances Message-ID: <20200323190505.GB632476@kroah.com> References: <20200323150007.7487-1-srinivas.kandagatla@linaro.org> <20200323150007.7487-6-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200323150007.7487-6-srinivas.kandagatla@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 23, 2020 at 03:00:07PM +0000, Srinivas Kandagatla wrote: > From: Nicholas Johnson > > There is at least one real-world use-case for write-only nvmem > instances. Refer to 03cd45d2e219 ("thunderbolt: Prevent crash if > non-active NVMem file is read"). > > Add support for write-only nvmem instances by adding attrs for 0200. > > Change nvmem_register() to abort if NULL group is returned from > nvmem_sysfs_get_groups(). > > Return NULL from nvmem_sysfs_get_groups() in invalid cases. > > Signed-off-by: Nicholas Johnson > Signed-off-by: Srinivas Kandagatla > --- > drivers/nvmem/core.c | 10 +++++-- > drivers/nvmem/nvmem-sysfs.c | 56 +++++++++++++++++++++++++++++++------ > 2 files changed, 56 insertions(+), 10 deletions(-) > > diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c > index 77d890d3623d..ddc7be5149d5 100644 > --- a/drivers/nvmem/core.c > +++ b/drivers/nvmem/core.c > @@ -381,6 +381,14 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) > nvmem->type = config->type; > nvmem->reg_read = config->reg_read; > nvmem->reg_write = config->reg_write; > + nvmem->dev.groups = nvmem_sysfs_get_groups(nvmem, config); > + if (!nvmem->dev.groups) { > + ida_simple_remove(&nvmem_ida, nvmem->id); > + gpiod_put(nvmem->wp_gpio); > + kfree(nvmem); > + return ERR_PTR(-EINVAL); > + } > + > if (!config->no_of_node) > nvmem->dev.of_node = config->dev->of_node; > > @@ -395,8 +403,6 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) > nvmem->read_only = device_property_present(config->dev, "read-only") || > config->read_only || !nvmem->reg_write; > > - nvmem->dev.groups = nvmem_sysfs_get_groups(nvmem, config); > - > device_initialize(&nvmem->dev); > > dev_dbg(&nvmem->dev, "Registering nvmem device %s\n", config->name); > diff --git a/drivers/nvmem/nvmem-sysfs.c b/drivers/nvmem/nvmem-sysfs.c > index 8759c4470012..9728da948988 100644 > --- a/drivers/nvmem/nvmem-sysfs.c > +++ b/drivers/nvmem/nvmem-sysfs.c > @@ -202,16 +202,49 @@ static const struct attribute_group *nvmem_ro_root_dev_groups[] = { > NULL, > }; > > +/* write only permission, root only */ > +static struct bin_attribute bin_attr_wo_root_nvmem = { > + .attr = { > + .name = "nvmem", > + .mode = 0200, > + }, > + .write = bin_attr_nvmem_write, > +}; You are adding a new sysfs file without a Documentation/ABI/ new entry as well? > + > +static struct bin_attribute *nvmem_bin_wo_root_attributes[] = { > + &bin_attr_wo_root_nvmem, > + NULL, > +}; > + > +static const struct attribute_group nvmem_bin_wo_root_group = { > + .bin_attrs = nvmem_bin_wo_root_attributes, > + .attrs = nvmem_attrs, > +}; > + > +static const struct attribute_group *nvmem_wo_root_dev_groups[] = { > + &nvmem_bin_wo_root_group, > + NULL, > +}; > + > const struct attribute_group **nvmem_sysfs_get_groups( > struct nvmem_device *nvmem, > const struct nvmem_config *config) > { > - if (config->root_only) > - return nvmem->read_only ? > - nvmem_ro_root_dev_groups : > - nvmem_rw_root_dev_groups; > + /* Read-only */ > + if (nvmem->reg_read && (!nvmem->reg_write || nvmem->read_only)) > + return config->root_only ? > + nvmem_ro_root_dev_groups : nvmem_ro_dev_groups; > + > + /* Read-write */ > + if (nvmem->reg_read && nvmem->reg_write && !nvmem->read_only) > + return config->root_only ? > + nvmem_rw_root_dev_groups : nvmem_rw_dev_groups; > + > + /* Write-only, do not honour request for global writable entry */ > + if (!nvmem->reg_read && nvmem->reg_write && !nvmem->read_only) > + return config->root_only ? nvmem_wo_root_dev_groups : NULL; What is this supposed to be doing, I am totally lost. greg k-h