From patchwork Tue Aug 11 11:03:12 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 6991561 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 0A6C2C05AC for ; Tue, 11 Aug 2015 11:05:38 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 28B3E205BE for ; Tue, 11 Aug 2015 11:05:37 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3799020430 for ; Tue, 11 Aug 2015 11:05:36 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZP7LM-0002PG-Qt; Tue, 11 Aug 2015 11:03:44 +0000 Received: from mail-wi0-f170.google.com ([209.85.212.170]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZP7LK-0002Kz-DE for linux-arm-kernel@lists.infradead.org; Tue, 11 Aug 2015 11:03:43 +0000 Received: by wicja10 with SMTP id ja10so70530005wic.1 for ; Tue, 11 Aug 2015 04:03:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=fZDWq5rf5LTX1bIFyE2i+XltixVwpgfmHKwm4fHeLik=; b=AidfmayqvjlldFusg53Cd0y8Lbt/2U6KzrKlIpbmUFeGG5tH4bMgQK7XFK3r8zvZxz TQ3s21uqpoRHiOlMczHa8ypOqbC+iIZE+NST1gcgCycGUX8Dh2CGThrWOPS+mo7SSn7k owYS/RypLgz2XJtqX2l8tBP9b5uU8Moysr+eTVef6HUZ9yr/xNguRIobnRfpNBa+rJ15 QnXuy4TrZEhL/URgdghX4ayXD+PjR5YIHhk26h2hdmf5/L77A17gasvFTxkEfxfqkMW9 GiWInJbVdi1QoZ5BFINf6uSBnvZU34fDWyn2igEX8Ym0gvMOJS/e8/+U1bR795NQi8gZ qqFA== X-Gm-Message-State: ALoCoQnLhdBY7hM/477NVEAyJ2VeX8++kcdY1M/D9b62D9hnX9807zev9nRE6LstOBCG4zdBlKsp X-Received: by 10.180.83.72 with SMTP id o8mr35749140wiy.27.1439291000789; Tue, 11 Aug 2015 04:03:20 -0700 (PDT) Received: from localhost.localdomain (host-92-13-246-184.as43234.net. [92.13.246.184]) by smtp.gmail.com with ESMTPSA id ft5sm18412591wib.4.2015.08.11.04.03.19 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 11 Aug 2015 04:03:20 -0700 (PDT) From: Srinivas Kandagatla To: Greg Kroah-Hartman Subject: [PATCH RFC 1/3] nvmem: make default user binary file root-access only Date: Tue, 11 Aug 2015 12:03:12 +0100 Message-Id: <1439290992-18283-1-git-send-email-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1439290931-18232-1-git-send-email-srinivas.kandagatla@linaro.org> References: <1439290931-18232-1-git-send-email-srinivas.kandagatla@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150811_040342_614861_A69AE84A X-CRM114-Status: GOOD ( 16.90 ) X-Spam-Score: -2.6 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrew Lunn , arnd@arndb.de, khilman@kernel.org, devicetree@vger.kernel.org, linux-api@vger.kernel.org, s.hauer@pengutronix.de, sboyd@codeaurora.org, linux-kernel@vger.kernel.org, maitysanchayan@gmail.com, pantelis.antoniou@konsulko.com, Rob Herring , Srinivas Kandagatla , Mark Brown , p.zabel@pengutronix.de, linux-arm-msm@vger.kernel.org, mporter@konsulko.com, linux-arm-kernel@lists.infradead.org, wxt@rock-chips.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP As required by many providers like at24/at25/mxs-ocotp/qfprom and may be other providers would want to allow root-only to read the nvmem content. So making the defaults to be root-only access would address the request and also provide flexibility to providers to specify there own permissions on top of the root-only using the perm flag in nvmem_config. Making this dynamic did cut down lot of static binary attributes in the code. Signed-off-by: Srinivas Kandagatla --- drivers/nvmem/core.c | 53 ++++++++++------------------------------------------ 1 file changed, 10 insertions(+), 43 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 35a42bb..103f6aa 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -31,6 +31,7 @@ struct nvmem_device { struct regmap *regmap; struct module *owner; struct device dev; + struct bin_attribute bin; int stride; int word_size; int ncells; @@ -109,52 +110,15 @@ static ssize_t bin_attr_nvmem_write(struct file *filp, struct kobject *kobj, } /* default read/write permissions */ -static struct bin_attribute bin_attr_rw_nvmem = { +static struct bin_attribute bin_attr_template = { .attr = { .name = "nvmem", - .mode = S_IWUSR | S_IRUGO, + .mode = S_IRUSR, }, .read = bin_attr_nvmem_read, .write = bin_attr_nvmem_write, }; -static struct bin_attribute *nvmem_bin_rw_attributes[] = { - &bin_attr_rw_nvmem, - NULL, -}; - -static const struct attribute_group nvmem_bin_rw_group = { - .bin_attrs = nvmem_bin_rw_attributes, -}; - -static const struct attribute_group *nvmem_rw_dev_groups[] = { - &nvmem_bin_rw_group, - NULL, -}; - -/* read only permission */ -static struct bin_attribute bin_attr_ro_nvmem = { - .attr = { - .name = "nvmem", - .mode = S_IRUGO, - }, - .read = bin_attr_nvmem_read, -}; - -static struct bin_attribute *nvmem_bin_ro_attributes[] = { - &bin_attr_ro_nvmem, - NULL, -}; - -static const struct attribute_group nvmem_bin_ro_group = { - .bin_attrs = nvmem_bin_ro_attributes, -}; - -static const struct attribute_group *nvmem_ro_dev_groups[] = { - &nvmem_bin_ro_group, - NULL, -}; - static void nvmem_release(struct device *dev) { struct nvmem_device *nvmem = to_nvmem_device(dev); @@ -346,10 +310,8 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) nvmem->read_only = of_property_read_bool(np, "read-only") | config->read_only; - - nvmem->dev.groups = nvmem->read_only ? nvmem_ro_dev_groups : - nvmem_rw_dev_groups; - + nvmem->bin = bin_attr_template; + nvmem->bin.attr.mode = nvmem->read_only ? : (S_IRUSR | S_IWUSR); device_initialize(&nvmem->dev); dev_dbg(&nvmem->dev, "Registering nvmem device %s\n", config->name); @@ -361,6 +323,10 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) return ERR_PTR(rval); } + rval = device_create_bin_file(&nvmem->dev, &nvmem->bin); + if (rval) + dev_err(&nvmem->dev, "Failed to create nvmem binary file\n"); + if (config->cells) nvmem_add_cells(nvmem, config); @@ -385,6 +351,7 @@ int nvmem_unregister(struct nvmem_device *nvmem) mutex_unlock(&nvmem_mutex); nvmem_device_remove_all_cells(nvmem); + device_remove_bin_file(&nvmem->dev, &nvmem->bin); device_del(&nvmem->dev); return 0;