From patchwork Wed Oct 7 11:00:47 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 54578 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f199.google.com (mail-lb0-f199.google.com [209.85.217.199]) by patches.linaro.org (Postfix) with ESMTPS id AC68822FF8 for ; Wed, 7 Oct 2015 11:00:59 +0000 (UTC) Received: by lbcao8 with SMTP id ao8sf5145458lbc.1 for ; Wed, 07 Oct 2015 04:00:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=jpNMXNqRXrc4QFGul48nZ9GIy1JUeX9VITK892Ap1Os=; b=f9m/4C61RF40tdwmAchInbHkClB/rl6p93+G/H55i/cOk+GFcmQ8NeoPrIM6bXmEPa N3khKnxnhOwD+OUFT3PQZLNWNVv8TYC02Jfq84NQKgiL155KdsCh8gxVSa7zX5dHu5cm eHm5jtjach7xkAR7BU/fCcsHff9s8ZtFci05futENKzzE40mchYOEcb6sOTCKWXvkCbu 6vudV2Icjhvh/JL9vnF3CHm5dhVLBVH0aptBzF+LkPkWQRuKocJD7GuGG6jKofOQKc8l WJSN/Z9sjykTCcSgh2kkaeQn12+VDeXhRy8c9YfL1M2lzC4azI4knDZ1KAqSsO8CCwNR GvfA== X-Gm-Message-State: ALoCoQkvgh8Ankaz0zMFZGQDX+clDwKx4+w4Ng2FKfDXU2clAXyLgjEKPEieT4dXQZIChhatDBNJ X-Received: by 10.112.198.33 with SMTP id iz1mr94998lbc.8.1444215658296; Wed, 07 Oct 2015 04:00:58 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.153.196 with SMTP id b187ls51153lfe.80.gmail; Wed, 07 Oct 2015 04:00:58 -0700 (PDT) X-Received: by 10.112.158.1 with SMTP id wq1mr204962lbb.67.1444215658127; Wed, 07 Oct 2015 04:00:58 -0700 (PDT) Received: from mail-lb0-f170.google.com (mail-lb0-f170.google.com. [209.85.217.170]) by mx.google.com with ESMTPS id an1si3641180lbc.68.2015.10.07.04.00.58 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Oct 2015 04:00:58 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.170 as permitted sender) client-ip=209.85.217.170; Received: by lbwr8 with SMTP id r8so7562443lbw.2 for ; Wed, 07 Oct 2015 04:00:58 -0700 (PDT) X-Received: by 10.25.205.198 with SMTP id d189mr150782lfg.72.1444215657998; Wed, 07 Oct 2015 04:00:57 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp2373318lbq; Wed, 7 Oct 2015 04:00:57 -0700 (PDT) X-Received: by 10.66.221.104 with SMTP id qd8mr399914pac.155.1444215656949; Wed, 07 Oct 2015 04:00:56 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id vi4si56875225pbc.209.2015.10.07.04.00.56; Wed, 07 Oct 2015 04:00:56 -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; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753547AbbJGLAx (ORCPT + 30 others); Wed, 7 Oct 2015 07:00:53 -0400 Received: from mail-wi0-f176.google.com ([209.85.212.176]:34156 "EHLO mail-wi0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750947AbbJGLAv (ORCPT ); Wed, 7 Oct 2015 07:00:51 -0400 Received: by wicfx3 with SMTP id fx3so206578315wic.1 for ; Wed, 07 Oct 2015 04:00:50 -0700 (PDT) X-Received: by 10.180.85.164 with SMTP id i4mr1177044wiz.54.1444215650646; Wed, 07 Oct 2015 04:00:50 -0700 (PDT) Received: from localhost.localdomain (host-92-13-246-184.as43234.net. [92.13.246.184]) by smtp.gmail.com with ESMTPSA id m6sm1357689wif.11.2015.10.07.04.00.49 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 07 Oct 2015 04:00:50 -0700 (PDT) From: Srinivas Kandagatla To: gregkh@linuxfoundation.org Cc: maxime.ripard@free-electrons.com, linux-kernel@vger.kernel.org, andrew@lunn.ch, wxt@rock-chips.com, stefan.wahren@i2se.com, pantelis.antoniou@konsulko.com, maitysanchayan@gmail.com, p.zabel@pengutronix.de, s.hauer@pengutronix.de, srinivas.kandagatla@linaro.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 1/3] nvmem: core: make default user binary file root-access only Date: Wed, 7 Oct 2015 12:00:47 +0100 Message-Id: <1444215647-10836-1-git-send-email-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1444215536-10783-1-git-send-email-srinivas.kandagatla@linaro.org> References: <1444215536-10783-1-git-send-email-srinivas.kandagatla@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: srinivas.kandagatla@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.170 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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 | 52 +++++++++++----------------------------------------- 1 file changed, 11 insertions(+), 41 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 6fd4e5a..0a70e31 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,9 +310,10 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) nvmem->read_only = of_property_read_bool(np, "read-only") | config->read_only; + nvmem->bin = bin_attr_template; - nvmem->dev.groups = nvmem->read_only ? nvmem_ro_dev_groups : - nvmem_rw_dev_groups; + if (!nvmem->read_only) + nvmem->bin.attr.mode |= S_IWUSR; device_initialize(&nvmem->dev); @@ -361,6 +326,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 +354,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;