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: 52302 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f200.google.com (mail-lb0-f200.google.com [209.85.217.200]) by patches.linaro.org (Postfix) with ESMTPS id 68A8C22DD6 for ; Tue, 11 Aug 2015 11:03:58 +0000 (UTC) Received: by lbck9 with SMTP id k9sf19577880lbc.0 for ; Tue, 11 Aug 2015 04:03:57 -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=q948oSZm09gQzu7y/ziiVPTDkBl7JGC/LD4eY67wz+M=; b=fjVzzMm9SPzqdsJNmnrvycfcvdptrPbhdqqP0CZGx7yHrlCA33BEnwt8GNH6mgTTy7 YE6NPGXFmHENWNvLF0Gptc/Yi04Uquini+dNm7ztDivdg7Pcs7q+r1k9fbvOznWHjfen YvT9+bkw41DfQRlV6yrXQ5tUPqItUv4WfXSiIsTVZRg0wZWUoAAAKBGYFvzJhT58LJXU yS6ebLCTLc92SEwfOfCE/wcsUsHn7YqDIrC1B6i2tZGkkV71YecWIvSPIRzD3ZUhbFKG dNibmnO0q/w3Ecb9YqN84pHVyw7IQCBbpnWUq0n6qXofSvDAgaG+TjN4udRBI97p76Mb +yFQ== X-Gm-Message-State: ALoCoQnmALoJG6W9WiabEQHiz/ZzI2ASPKfWMaX4BvwfqdgrYNs7rbS4ZEpW4FC7oMfz6g2fjsk5 X-Received: by 10.152.115.196 with SMTP id jq4mr7801076lab.1.1439291037393; Tue, 11 Aug 2015 04:03:57 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.9.232 with SMTP id d8ls832783lab.13.gmail; Tue, 11 Aug 2015 04:03:57 -0700 (PDT) X-Received: by 10.112.148.130 with SMTP id ts2mr25682941lbb.17.1439291037090; Tue, 11 Aug 2015 04:03:57 -0700 (PDT) Received: from mail-lb0-f174.google.com (mail-lb0-f174.google.com. [209.85.217.174]) by mx.google.com with ESMTPS id bm5si1098707lbc.30.2015.08.11.04.03.57 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Aug 2015 04:03:57 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.174 as permitted sender) client-ip=209.85.217.174; Received: by lbbpu9 with SMTP id pu9so83583900lbb.3 for ; Tue, 11 Aug 2015 04:03:57 -0700 (PDT) X-Received: by 10.152.36.102 with SMTP id p6mr25537379laj.19.1439291036931; Tue, 11 Aug 2015 04:03:56 -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.7.198 with SMTP id l6csp2449055lba; Tue, 11 Aug 2015 04:03:55 -0700 (PDT) X-Received: by 10.70.134.99 with SMTP id pj3mr24557406pdb.3.1439291034256; Tue, 11 Aug 2015 04:03:54 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e3si2876335pdf.91.2015.08.11.04.03.53; Tue, 11 Aug 2015 04:03:54 -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 S964845AbbHKLDY (ORCPT + 28 others); Tue, 11 Aug 2015 07:03:24 -0400 Received: from mail-wi0-f174.google.com ([209.85.212.174]:34990 "EHLO mail-wi0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964787AbbHKLDW (ORCPT ); Tue, 11 Aug 2015 07:03:22 -0400 Received: by wicne3 with SMTP id ne3so55815068wic.0 for ; Tue, 11 Aug 2015 04:03:20 -0700 (PDT) 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 Cc: Andrew Lunn , wxt@rock-chips.com, linux-api@vger.kernel.org, Rob Herring , sboyd@codeaurora.org, arnd@arndb.de, linux-arm-kernel@lists.infradead.org, khilman@kernel.org, s.hauer@pengutronix.de, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, mporter@konsulko.com, pantelis.antoniou@konsulko.com, devicetree@vger.kernel.org, Mark Brown , maitysanchayan@gmail.com, p.zabel@pengutronix.de, Srinivas Kandagatla 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> 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.174 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 | 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;