Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp1704122imj; Thu, 14 Feb 2019 10:35:27 -0800 (PST) X-Google-Smtp-Source: AHgI3IbF4sSV1a3uvhXGzoGDUasyhdmda1/UxOdGVORUdNw4NxN6Pl9vx+5DyRF+ZWQhHSq9N0Yc X-Received: by 2002:a17:902:32b:: with SMTP id 40mr5397905pld.327.1550169327606; Thu, 14 Feb 2019 10:35:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550169327; cv=none; d=google.com; s=arc-20160816; b=CSV/W5dhBiiGO6cWiMnBQUrgvzb6pVrcMa6HVS8V5ErgedPPUO40pHMJ+bLCvt64/k kSryaC81wqa4/INDFwZ5T5B25zn0H0PZzv+iNcBwXIXWkV9Idh9ND+0/hZ/4A6J1Mbma qxJnwRnvqjZmnf/VbKsyLNNF1HFUzmxLa/8kxV25oNH0c342ernIHXbKB97c3ujIX+6P 1mf8EI2gOoZ2AydOHobh9m9aS5dzk9ajeuuiSsGZC/nTQF3y6mGkPoovN834OgFL8IjK fbIyVdJW9esAw9zhkNpYuOG+BArbL4u+nq6PkoDXDtatNtbSnF0IkiffBZQ0JJ7m/r9B T8Ug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=Qh4efhAQ+7yfIkcC5m1CpQX6yscsXGJAuuZKxq3YWVo=; b=nVHt2ZAbtbB5+wVXv68fcUAlq1FaiBo5oYLy14goWh9d+WLzI8U7Fbq2556PHjdJU/ /6qoedzZLDW3U8udMl/CY1g3bXvPtvx0mUmMRORkQ7ViQKBEt0vH1k+r6lMxIm33jAoI SRcFy4toREK7UE6nvzO/Gn3HeRudnW/CPyUyh+SLMIiwIrdp7xLbnA4h0pEgkFhs5Tj2 LBDgFLHZaIi0/XgI95zvF41r4RdH2mNK5ppHfKIVnNRIVSop/XJ+qXcsHzI1XslNp16u x53ygtWtt5IJGWX8eZz/x91h3nXGQRjMlxlO+CZihBvCSwXA9nrNy447KqQxwecACsz7 Aqtg== ARC-Authentication-Results: i=1; mx.google.com; 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 f10si2906602pgl.528.2019.02.14.10.35.11; Thu, 14 Feb 2019 10:35:27 -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; 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 S1729347AbfBNL0X (ORCPT + 99 others); Thu, 14 Feb 2019 06:26:23 -0500 Received: from www.osadl.org ([62.245.132.105]:37553 "EHLO www.osadl.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727097AbfBNL0X (ORCPT ); Thu, 14 Feb 2019 06:26:23 -0500 Received: from debian01.hofrr.at (178.115.242.59.static.drei.at [178.115.242.59]) by www.osadl.org (8.13.8/8.13.8/OSADL-2007092901) with ESMTP id x1EBQ7jh020439; Thu, 14 Feb 2019 12:26:07 +0100 From: Nicholas Mc Guire To: Jonathan Corbet Cc: Greg Kroah-Hartman , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Nicholas Mc Guire Subject: [PATCH RFC] sysfs.txt: add note on available attribute macros Date: Thu, 14 Feb 2019 12:21:50 +0100 Message-Id: <1550143310-17463-1-git-send-email-hofrat@osadl.org> X-Mailer: git-send-email 2.1.4 X-Spam-Status: No, score=-1.9 required=6.0 tests=BAYES_00 autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on www.osadl.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The common cases of attributes should probably be using the __ATTR_XXX macros to make code more concise and readable but the current sysfs.txt does not point developers to those convenience macros. Further there is no note in sysfs.txt currently explaining why trying to set a sysfs file to mode 0666 will fail. Signed-off-by: Nicholas Mc Guire --- Note quite sure if this is the right place to place the note on mode 0666 but it should be somewhere as any attempt to set 0666 will be reverted to 0664. Documentation/filesystems/sysfs.txt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Documentation/filesystems/sysfs.txt b/Documentation/filesystems/sysfs.txt index 41411b0..c246142 100644 --- a/Documentation/filesystems/sysfs.txt +++ b/Documentation/filesystems/sysfs.txt @@ -116,6 +116,22 @@ static struct device_attribute dev_attr_foo = { .store = store_foo, }; +Note as stated in include/linux/kernel.h "OTHER_WRITABLE? Generally +considered a bad idea." so trying to set a sysfs file writable for +everyone will fail reverting to mode 0664. + +For this common cases sysfs.h provides convenience macros to +make defining attributes easier as well as making code more +concise and readable. The above case could be shortened to: + +static struct device_attribute dev_attr_foo = __ATTR_RW(foo); + +the list of helpers available is: +__ATTR_RO(name): same as above with mode 0444 +__ATTR_WO(name): same as above with mode 0200 +__ATTR_RO_MODE(name, mode): allowing to pass in a specific mode +__ATTR_RW(name): setting mode to 0644 +__ATTR_NULL: which sets the name to NULL Subsystem-Specific Callbacks ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- 2.1.4