Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp501010pxb; Wed, 27 Jan 2021 13:08:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJxK+l3VM9azTSuEV2MQQb+NE6jqBoA8GlvEhVRZgGYRP2DLI3BjlmfxxSGXe3h+kw0+5eM1 X-Received: by 2002:a17:906:944a:: with SMTP id z10mr7968344ejx.96.1611781711978; Wed, 27 Jan 2021 13:08:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611781711; cv=none; d=google.com; s=arc-20160816; b=Nu/J6kkkvsfXRgU0s/Ku6spnX5dQZtJmpNtEd0AVkqhRQLF72v0W4RYFhZAe2qi4GJ d4Usb0+tgqQOWlqhcVfitA+w9qpkMr5tUUbEtVWCpdnK1OJ4m0zNkTAulVRFOuEHIMLC yUWyqSZggKDZ75q6PhiOgvFPT53BTX4T3lWwuT2P11t5YvsiYvjd6Qw5xQDBfp9ULsvc VAQr6ESFn3gRISGWDBy3ZW45PK2gPv0q/67JiGCTyOczmLEqEpI8IpYcZ9yQ8aSF2R9k sAqNGNj7tA+NEdFLVz/eWSZ3DbTaPlAAsuB+eYo3qQz2JWVpuK09cM5YXshu29cD8GPC pFkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature; bh=YGrPRxNt+RP6h4OeOrtja6PVCsuV/WKXvcTlJJ9DTbk=; b=cyn57FR1jxqjXQXOtIPm2MJ0wQPLEiq7QYYbQNa503fIxGN40SMcIGUk7TCAv58fX2 rlVuMfB7T5qexOKLYg8R3J4AJ7k5IM+khkcLR9PUrIk6rBMBcNJQqRYcJTZOhd+eDmyn 9tSJJ4KQCUyDh8/dFFOGoD8KFcB4RYtzDU0BBxlaern2FkrEGIN9JvndQZyl1Wx551yH aAFVD6p/tqvC4cEIOs4gUsV0sqzMUDv/ZN4362q3OBd757oLwmUTekXCjzYxeQ49n/sE 0F6f1N0VxEXfXFm8OyoiQQe5hI79FtvhA/jyC2JYuDBIOS/wMShcbeaGedcPwLScM+Vs pdGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=JLGEnAvh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h19si1612090edt.159.2021.01.27.13.08.06; Wed, 27 Jan 2021 13:08:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=JLGEnAvh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231555AbhA0FIt (ORCPT + 99 others); Wed, 27 Jan 2021 00:08:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343633AbhA0EUa (ORCPT ); Tue, 26 Jan 2021 23:20:30 -0500 Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF01BC061573; Tue, 26 Jan 2021 20:19:50 -0800 (PST) Received: by mail-pg1-x52e.google.com with SMTP id r38so690699pgk.13; Tue, 26 Jan 2021 20:19:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=YGrPRxNt+RP6h4OeOrtja6PVCsuV/WKXvcTlJJ9DTbk=; b=JLGEnAvhAwJZfHwdLlhmb0DSl4UZi3OZv3iWekFOGR3qFRUyW0DTs/gCwJjVdH9heU g3IgtsRjNM8IbIG0d1R3jECKK4vMQQFCYaoC8iW/hEPmLOtYz9sBuh/rnlh7x8ieQRRk SlvIypskATZnjm/Lvpye3dPgwr6E4tlcV8WjjUzJmDzgz0jmx8ZfAZF40RAAHTYiI2PE /fpvQt9yoAMz03LPgmg76lrj4omYJPVJuIhIKoj5QTwLbnkgJsZwkDSyvSWM9+UtGRbp LGaaekePubsHLZw3pC7kQtXYcpPAxlCbkIHqcniGQmG/7H3roHhg9QfUuKdRO5IOg6nG FQnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=YGrPRxNt+RP6h4OeOrtja6PVCsuV/WKXvcTlJJ9DTbk=; b=dDgzy0jBESRsnAk7JVQS2od2UFBI1bj5U7sCikZ4Px3Pz9mIOg1LKQk74iW/jotQIR L8nvR1tQqaIUpyf2lGXHDg7heyOW1oYmf6BKpyvv4zkYQpHW5N6jDL4y+4Frl0MAUJE7 jmEDnLrSPwkMFk6LsRkshCx/bTnx+DECQMpNQhoRyQLgfI8IsZ8MnYJaTZ7Xc2mmoihH ecZ3UFxpe821lKAOFysGubFuJ5/GL5NXs21oGOTWS8VQSE8VDCBnxd7loJsCGEvuD8jM 0JCWIiSgbR0gjS3g/idDO+Spaf6Hyq+AyO4wP7hiEbqHkyYFxAhAz3BPpjxMapF3ZJUa aX/w== X-Gm-Message-State: AOAM531NC0+Khj/y4HZqliD/CX+QRCAHm4guZoS2osNP7m5Pe7wFLsLF bPrWQoMwm33Nv0TeatVrNjU= X-Received: by 2002:aa7:80c6:0:b029:1b6:92ae:a199 with SMTP id a6-20020aa780c60000b02901b692aea199mr8403118pfn.71.1611721190388; Tue, 26 Jan 2021 20:19:50 -0800 (PST) Received: from lenovo.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id m10sm397760pjs.25.2021.01.26.20.19.34 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Jan 2021 20:19:49 -0800 (PST) From: Orson Zhai To: Jonathan Corbet , Mauro Carvalho Chehab , Joe Perches , Denis Efremov , Greg Kroah-Hartman , "David S. Miller" , Christian Brauner , Dan Williams , Sourabh Jain Cc: Orson Zhai , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Orson Zhai Subject: [PATCH] include: sysfs: Add macro to assign show for RO attributes Date: Wed, 27 Jan 2021 12:19:22 +0800 Message-Id: <1611721162-29982-1-git-send-email-orsonzhai@gmail.com> X-Mailer: git-send-email 2.7.4 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In some circumstances, multiple __ATTR_RO attributes need to be assigned with a single show function. Add this macro to make life easier with simple code. Signed-off-by: Orson Zhai --- Documentation/filesystems/sysfs.rst | 2 ++ include/linux/sysfs.h | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/Documentation/filesystems/sysfs.rst b/Documentation/filesystems/sysfs.rst index 004d490..0e2274a 100644 --- a/Documentation/filesystems/sysfs.rst +++ b/Documentation/filesystems/sysfs.rst @@ -141,6 +141,8 @@ __ATTR_RO_MODE(name, mode): fore more restrictive RO access currently only use case is the EFI System Resource Table (see drivers/firmware/efi/esrt.c) +__ATTR_RO_SHOW(name, show): + assumes default mode 0444 with specified show. __ATTR_RW(name): assumes default name_show, name_store and setting mode to 0644. diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h index 2caa34c..c851592 100644 --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h @@ -117,6 +117,11 @@ struct attribute_group { .show = _name##_show, \ } +#define __ATTR_RO_SHOW(_name, _show) { \ + .attr = { .name = __stringify(_name), .mode = 0444 }, \ + .show = _show, \ +} + #define __ATTR_RO_MODE(_name, _mode) { \ .attr = { .name = __stringify(_name), \ .mode = VERIFY_OCTAL_PERMISSIONS(_mode) }, \ -- 2.7.4