Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp587163pxb; Wed, 27 Jan 2021 15:58:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJwV/piL796u1HAItxO0ocRC4B1hOq2KTniEytTCokk6Vu1ernWjlXFPDYE2l3+06G0WsaM0 X-Received: by 2002:a17:906:7cc:: with SMTP id m12mr8252421ejc.386.1611791906007; Wed, 27 Jan 2021 15:58:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611791905; cv=none; d=google.com; s=arc-20160816; b=PPP0C2gJxcZJiLE2t48f98O5aXQAIu5KMZbU1rG4litzbJg57KjWoh3nWKez+mhS6+ OdymAwqU8p3ek3Yek034sKa2clAi/RO96Tj5JTDRLV6E2ZpamIGU85rCQNnnfSZvuRAS oQQRJKbA/sqmR6Sis49eezem9X8NuMGgyeSKZwTVsh4s86OaJ6IYYRTbYKkRGhlUuErR h8/ngKch23YHG/cuJXrflXabhdF1bBQLdpR1X5ailbmcKdGpNcobO/JpkuEwXK/Uk9Hk W4ESAQN4wiythxtJH83T8W/QlKSBGh0ewAyncAMceg/Gnnh+QN8J8vbi+GuSD4PdG6Es u1HQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:mail-followup-to:message-id:subject:cc:to :from:date:dkim-signature; bh=AgqQhBKOPlB7DDmVKm31upDgAqlEXZFPIdQm63gX/8E=; b=nC0LGx4QM61ShRKAo1DH/jyrOY5D88Ya9qaxB1rUQJDhQje/6HY3wYGFCfE/vpZPUi MI3zc+AhgfE+zU2cT1eEeUAurbkzY43RAOo0n/BFeFv06zCy6yJRfObuexRZ+Y5frMOQ vJxNIqAT96N+YeeFUZ6JWkNlZ7sdqMn7pil+yZa3kgF2QnasSFuztSUm98pSHKxZgVFn vorQdkOQHgDp0dsr8kjLqEfekNz+wjYqwhAkc2V1Aa2I7R84juDDsZ05SguRyt38OmAg HqYrf+PJbH1rU7FbUOftZjvMQI6B3OUY9UXTmbAUexSrEkRMO1+TLAAEn3sxVzsPAZ1i bpgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=V4St0wI5; 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 y11si1642544ejd.56.2021.01.27.15.58.02; Wed, 27 Jan 2021 15:58:25 -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=V4St0wI5; 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 S238182AbhA0Myp (ORCPT + 99 others); Wed, 27 Jan 2021 07:54:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238055AbhA0Mwc (ORCPT ); Wed, 27 Jan 2021 07:52:32 -0500 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3AB1C06174A; Wed, 27 Jan 2021 04:51:50 -0800 (PST) Received: by mail-pj1-x1031.google.com with SMTP id a20so1200447pjs.1; Wed, 27 Jan 2021 04:51:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to:user-agent; bh=AgqQhBKOPlB7DDmVKm31upDgAqlEXZFPIdQm63gX/8E=; b=V4St0wI5fQKkXrZ74W0M3bU05pM5Oq4IcZbxR89XfPEjNctU+Jb8U7axZdD1r9xsf4 DgWYvvzln+j9ov0bZwsq6iCLVM6M2RsmVeTEB/pyDZHq89sNe4n74GNuyRnCV4AUk0KJ Cm0aJ6xaSSu6gpNkTHqG35Jv9/5bcWwVx9DboiYqyNDBSWFno4PU+s5BPk10eh4RYg4N sbOpeWhqRsXt02lLO7aQ9RDesvFJIRyLsk3R2vlK2QM6nuZb2SaYKo1FqlMxZAxIW+2u 64GHWw9ZvEm8oFasjVxw6hZzkCjgcP4qe4qFmZT41ob/DrtqjcegYyn9cjn+NWR7pm59 qENg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :in-reply-to:user-agent; bh=AgqQhBKOPlB7DDmVKm31upDgAqlEXZFPIdQm63gX/8E=; b=K2JYDdu/H8YafT80caXXLI59PQfkATOCU+HhSDgbESmzPkVbw6FmWt/CZ6pyrwVF3b Cw/LXcbDWvus64eNinLAULfbHvXxjrx6jX5Clgp0gA6pGHfuqU82P9vNhqToQz0MUOK9 Sz1Btk8uwrtgiBSYbFSEBgJDiK6sZIkUgmq36ZkkdIhLSgGjmauEkwmNfxHT13XA2vtu b713Wg6sfD5yyZbifKt6NaAtCL94gc245driGwz16oUZwIGiN02tHWumWTFynSIZA3CA qm/sio+jhmf+hqRwdk4wEvC6r9/KWfMLXFET46m0UVgKLivSs5f4S9Az5bcyD/0IieGr Q0MA== X-Gm-Message-State: AOAM531VUE72uFs4EcxhxVCT7IBbGTwMOvZ5HB20bjTw0h7evxOPicfb qxSJOx/V36VwYTbNwgBUAZc= X-Received: by 2002:a17:90a:670f:: with SMTP id n15mr5704625pjj.175.1611751910461; Wed, 27 Jan 2021 04:51:50 -0800 (PST) Received: from lenovo ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id me3sm1954459pjb.32.2021.01.27.04.51.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Jan 2021 04:51:49 -0800 (PST) Date: Wed, 27 Jan 2021 20:51:26 +0800 From: Orson Zhai To: Greg Kroah-Hartman Cc: Jonathan Corbet , Mauro Carvalho Chehab , Joe Perches , Denis Efremov , "David S. Miller" , Christian Brauner , Dan Williams , Sourabh Jain , Orson Zhai , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] include: sysfs: Add macro to assign show for RO attributes Message-ID: <20210127125126.GA7813@lenovo> Mail-Followup-To: Greg Kroah-Hartman , Jonathan Corbet , Mauro Carvalho Chehab , Joe Perches , Denis Efremov , "David S. Miller" , Christian Brauner , Dan Williams , Sourabh Jain , Orson Zhai , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org References: <1611721162-29982-1-git-send-email-orsonzhai@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 27, 2021 at 08:50:28AM +0100, Greg Kroah-Hartman wrote: > On Wed, Jan 27, 2021 at 12:19:22PM +0800, Orson Zhai wrote: > > 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, \ > > +} > > Do you have a real user for this? Using "raw" kobject attributes is Yes, I have found at least one user in current kernel code. Please refer to [1]. The author implemented a similar marcro __ATRR_MRO as mine, plus an __ATRR_MWO with specified restore. If this patch merged, I'd to replace his marcro with mine. > rare and should not be used often, so who needs this? Agree. But for some device drivers it might be useful without side effect. Another example is from Android increment-fs code out there. That driver has 3 sysfs attributes which shared with same show function which only prints "support" to userland. Best Regards, Orson > > thanks, > > greg k-h [1] https://elixir.bootlin.com/linux/v5.11-rc5/source/drivers/media/pci/ddbridge/ddbridge-core.c#L2735