Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp588032pxb; Wed, 27 Jan 2021 16:00:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJy8LA5xR5DZYZ73kjSCV1t/JjqmySXViqJc3WGMdemt3bBqagRi7IdXsnLLWbaZ64t2FUbB X-Received: by 2002:a17:906:7e49:: with SMTP id z9mr8663329ejr.447.1611792006256; Wed, 27 Jan 2021 16:00:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611792006; cv=none; d=google.com; s=arc-20160816; b=G9wuz/soWOM1A9HRSMug8yF7a+MOaencb3j7fiE9yHG2lCV+8JPYP4BP9keYApGSCy y7daAMrMiQlflhK3yR/hYOsFMAtqRwmyhqKxCDmmAQ5qUplDY4o0NGvdJO/RBeAMAH1p NHnbsIMMB25axQ/RXhz2Zfteop3zVPOEXsPP0HrwK1aNFcv8CFcP8jeGK/wf1HvrHZCm YcSvqjxtNflSrZhXY73zvgYCvzNrkPsU0SjnKeRfEnY3UrPSrVkFfqrIWrMjlhKQOKdS cx4s+uU3aIE/7/LE9/7HTw0muaxgj30x44giCBwAB9P5CnV9+SOzftAwifPGYrTjvj4A 0qVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:to:from:date:dkim-signature; bh=Qj8QcRRx8k/Y9ILu+ttGVe/CCzSxqGx1rQ2tTMsaZ30=; b=FgFTyJfdOraswPSrIKaBVvBiX8Tryb1byaehbN0eBgPm0ngKg/pF0MEmV6oLuQonjP NjDRE+zvYvRkiFJumaac8qH1eH48tCAAz+L2wcWfu+oLUvV/Lp7IxJDulw7gdvDRnnM6 g3zYxTEIzwLZVHuio5BDp+0zBqUPl+o1oFSAqyN9PWsJ3raH1ZxfUjFBteVIdggzSUIJ Ym3n/WHsXGkbCCSbv/czVo6x2sObdhXpSkdbT+tLdMmPiR4zDZfsLopHoPBdN94XkXIv fdgAgAUpTpDln1N4E/du53Q80FAlagk9cVWSUnhbvzZl1BrRH6eLNVR+HKalm8PleJ4D H2xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="i/J0XSdm"; 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=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g21si1680750edu.180.2021.01.27.15.59.42; Wed, 27 Jan 2021 16:00:06 -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=@linuxfoundation.org header.s=korg header.b="i/J0XSdm"; 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=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238521AbhA0Ndb (ORCPT + 99 others); Wed, 27 Jan 2021 08:33:31 -0500 Received: from mail.kernel.org ([198.145.29.99]:59360 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238477AbhA0NbB (ORCPT ); Wed, 27 Jan 2021 08:31:01 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 04BA1207A0; Wed, 27 Jan 2021 13:30:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1611754218; bh=PRPfyBQ4qTkyM5ldK/G+fxEfNZ+SuyxPadtIZ8ggCS8=; h=Date:From:To:Subject:References:In-Reply-To:From; b=i/J0XSdmNCwo8OkCHOIeKDGqBQYncNk8FULsNG5fhh2wty7WMMKvbJcOdDCM2Pe3z 0bKsYWFYNIrIFh2MGx9cLVHlOSlVvfDEkLN/K6HONMD4ifSpzyeBd8KfBuBUSv4jJ/ /jIJ7Uh/N7hqLWJcs5bTiqQ1H7BVXySLd1BBKFzY= Date: Wed, 27 Jan 2021 14:30:15 +0100 From: Greg Kroah-Hartman To: 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: References: <1611721162-29982-1-git-send-email-orsonzhai@gmail.com> <20210127125126.GA7813@lenovo> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210127125126.GA7813@lenovo> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 27, 2021 at 08:51:26PM +0800, Orson Zhai wrote: > 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. Ick, no, that should be using DEVICE_ATTR_RO() as it is a struct device attribute, not a "raw" kobject attribute. So that code should be fixed up anyway, no need for this macro :) > > 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. Drivers should NOT be ever using __ATTR* macros. That is not what they are there for. > 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. I can't take patches for out-of-tree code, sorry, you know this :) thanks, greg k-h