Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
From: "Thomas Weißschuh" <linux@weissschuh.net>
To: James Bottomley <James.Bottomley@hansenpartnership.com>
Cc: Xinhui.Pan@amd.com, airlied@gmail.com, ajd@linux.ibm.com,
	 alexander.deucher@amd.com, alison.schofield@intel.com,
	amd-gfx@lists.freedesktop.org,  arnd@arndb.de,
	bhelgaas@google.com, carlos.bilbao.osdev@gmail.com,
	 christian.koenig@amd.com, dan.j.williams@intel.com,
	dave.jiang@intel.com,  dave@stgolabs.net,
	david.e.box@linux.intel.com, decui@microsoft.com,
	 dennis.dalessandro@cornelisnetworks.com,
	dri-devel@lists.freedesktop.org, fbarrat@linux.ibm.com,
	 gregkh@linuxfoundation.org, haiyangz@microsoft.com,
	hdegoede@redhat.com,  ilpo.jarvinen@linux.intel.com,
	ira.weiny@intel.com, jgg@ziepe.ca, jonathan.cameron@huawei.com,
	 kys@microsoft.com, leon@kernel.org, linux-alpha@vger.kernel.org,
	 linux-cxl@vger.kernel.org, linux-hyperv@vger.kernel.org,
	linux-kernel@vger.kernel.org,  linux-mtd@lists.infradead.org,
	linux-pci@vger.kernel.org, linux-rdma@vger.kernel.org,
	 linux-scsi@vger.kernel.org, linux-usb@vger.kernel.org,
	linuxppc-dev@lists.ozlabs.org,  logang@deltatee.com,
	martin.petersen@oracle.com, mattst88@gmail.com,
	 miquel.raynal@bootlin.com, mwalle@kernel.org,
	naveenkrishna.chatradhi@amd.com,
	 platform-driver-x86@vger.kernel.org, pratyush@kernel.org,
	rafael@kernel.org,  richard.henderson@linaro.org, richard@nod.at,
	simona@ffwll.ch, srinivas.kandagatla@linaro.org,
	 tudor.ambarus@linaro.org, vigneshr@ti.com,
	vishal.l.verma@intel.com, wei.liu@kernel.org
Subject: Re: [PATCH v2 09/10] sysfs: bin_attribute: add const read/write callback variants
Date: Tue, 3 Dec 2024 17:11:10 +0100	[thread overview]
Message-ID: <5b589ddb-e3c9-40e1-987f-30ba81dc8ace@t-8ch.de> (raw)
In-Reply-To: <7ed3b713f8901398f52d7485d59613c19ea0e752.camel@HansenPartnership.com>

On 2024-12-03 11:06:16-0500, James Bottomley wrote:
> > diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
> > index
> > d17c473c1ef292875475bf3bdf62d07241c13882..d713a6445a6267145a7014f308d
> > f3bb25b8c3287 100644
> > --- a/include/linux/sysfs.h
> > +++ b/include/linux/sysfs.h
> > @@ -305,8 +305,12 @@ struct bin_attribute {
> >  	struct address_space *(*f_mapping)(void);
> >  	ssize_t (*read)(struct file *, struct kobject *, struct
> > bin_attribute *,
> >  			char *, loff_t, size_t);
> > +	ssize_t (*read_new)(struct file *, struct kobject *, const
> > struct bin_attribute *,
> > +			    char *, loff_t, size_t);
> >  	ssize_t (*write)(struct file *, struct kobject *, struct
> > bin_attribute *,
> >  			 char *, loff_t, size_t);
> > +	ssize_t (*write_new)(struct file *, struct kobject *,
> > +			     const struct bin_attribute *, char *,
> > loff_t, size_t);
> >  	loff_t (*llseek)(struct file *, struct kobject *, const
> > struct bin_attribute *,
> >  			 loff_t, int);
> >  	int (*mmap)(struct file *, struct kobject *, const struct
> > bin_attribute *attr,
> > @@ -325,11 +329,28 @@ struct bin_attribute {
> >   */
> >  #define sysfs_bin_attr_init(bin_attr) sysfs_attr_init(&(bin_attr)-
> > >attr)
> >  
> > +typedef ssize_t __sysfs_bin_rw_handler_new(struct file *, struct
> > kobject *,
> > +					   const struct
> > bin_attribute *, char *, loff_t, size_t);
> > +
> >  /* macros to create static binary attributes easier */
> >  #define __BIN_ATTR(_name, _mode, _read, _write, _size)
> > {		\
> >  	.attr = { .name = __stringify(_name), .mode = _mode
> > },		\
> > -	.read	=
> > _read,						\
> > -	.write	=
> > _write,						\
> > +	.read =
> > _Generic(_read,						\
> > +		__sysfs_bin_rw_handler_new * :
> > NULL,			\
> > +		default :
> > _read						\
> > +	),							
> > 	\
> > +	.read_new =
> > _Generic(_read,					\
> > +		__sysfs_bin_rw_handler_new * :
> > _read,			\
> > +		default :
> > NULL						\
> > +	),							
> > 	\
> > +	.write =
> > _Generic(_write,					\
> > +		__sysfs_bin_rw_handler_new * :
> > NULL,			\
> > +		default :
> > _write					\
> > +	),							
> > 	\
> > +	.write_new =
> > _Generic(_write,					\
> > +		__sysfs_bin_rw_handler_new * :
> > _write,			\
> > +		default :
> > NULL						\
> > +	),							
> > 	\
> >  	.size	=
> > _size,						\
> >  }
> 
> It's probably a bit late now, but you've done this the wrong way
> around.  What you should have done is added the const to .read/.write
> then added a .read_old/.write_old with the original function prototype
> and used _Generic() to switch between them.  Then when there are no
> more non const left, you can simply remove .read_old and .write_old
> without getting Linus annoyed by having to do something like this:
> 
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=e70140ba0d2b1a30467d4af6bcfe761327b9ec95

Not all users are using the macros to define their attributes.
(Nor do they want to)

These users would break with your suggestion.
Otherwise I agree.


Thomas

  reply	other threads:[~2024-12-03 16:11 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-03 17:03 [PATCH v2 00/10] sysfs: constify struct bin_attribute (Part 1) Thomas Weißschuh
2024-11-03 17:03 ` [PATCH v2 01/10] sysfs: explicitly pass size to sysfs_add_bin_file_mode_ns() Thomas Weißschuh
2024-11-03 17:03 ` [PATCH v2 02/10] sysfs: introduce callback attribute_group::bin_size Thomas Weißschuh
2024-11-05 16:12   ` Bjorn Helgaas
2024-11-06 19:27   ` Armin Wolf
2024-11-06 20:05   ` Krzysztof Wilczyński
2024-11-07  5:21     ` Greg Kroah-Hartman
2024-11-07 15:50       ` Krzysztof Wilczyński
2024-11-03 17:03 ` [PATCH v2 03/10] PCI/sysfs: Calculate bin_attribute size through bin_size() Thomas Weißschuh
2024-11-07 16:27   ` Bjorn Helgaas
2024-11-03 17:03 ` [PATCH v2 04/10] nvmem: core: calculate " Thomas Weißschuh
2024-11-08  9:58   ` Srinivas Kandagatla
2024-11-03 17:03 ` [PATCH v2 05/10] sysfs: treewide: constify attribute callback of bin_is_visible() Thomas Weißschuh
2024-11-04 13:25   ` Ilpo Järvinen
2024-11-04 13:52   ` Jason Gunthorpe
2024-11-04 14:56   ` Ira Weiny
2024-11-05  1:25   ` Martin K. Petersen
2024-11-05 15:26   ` Bjorn Helgaas
2024-11-07 17:20   ` Pratyush Yadav
2024-11-08  9:57   ` Srinivas Kandagatla
2024-11-03 17:03 ` [PATCH v2 06/10] sysfs: treewide: constify attribute callback of bin_attribute::mmap() Thomas Weißschuh
2024-11-04  1:24   ` Andrew Donnellan
2024-11-03 17:03 ` [PATCH v2 07/10] sysfs: treewide: constify attribute callback of bin_attribute::llseek() Thomas Weißschuh
2024-11-03 17:03 ` [PATCH v2 08/10] sysfs: implement all BIN_ATTR_* macros in terms of __BIN_ATTR() Thomas Weißschuh
2024-11-03 17:03 ` [PATCH v2 09/10] sysfs: bin_attribute: add const read/write callback variants Thomas Weißschuh
2024-12-03 16:06   ` James Bottomley
2024-12-03 16:11     ` Thomas Weißschuh [this message]
2024-11-03 17:03 ` [PATCH v2 10/10] driver core: Constify attribute arguments of binary attributes Thomas Weißschuh
2024-11-03 20:02 ` [PATCH v2 00/10] sysfs: constify struct bin_attribute (Part 1) Krzysztof Wilczyński
2024-11-05 16:15 ` Bjorn Helgaas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5b589ddb-e3c9-40e1-987f-30ba81dc8ace@t-8ch.de \
    --to=linux@weissschuh.net \
    --cc=James.Bottomley@hansenpartnership.com \
    --cc=Xinhui.Pan@amd.com \
    --cc=airlied@gmail.com \
    --cc=ajd@linux.ibm.com \
    --cc=alexander.deucher@amd.com \
    --cc=alison.schofield@intel.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=arnd@arndb.de \
    --cc=bhelgaas@google.com \
    --cc=carlos.bilbao.osdev@gmail.com \
    --cc=christian.koenig@amd.com \
    --cc=dan.j.williams@intel.com \
    --cc=dave.jiang@intel.com \
    --cc=dave@stgolabs.net \
    --cc=david.e.box@linux.intel.com \
    --cc=decui@microsoft.com \
    --cc=dennis.dalessandro@cornelisnetworks.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=fbarrat@linux.ibm.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=haiyangz@microsoft.com \
    --cc=hdegoede@redhat.com \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=ira.weiny@intel.com \
    --cc=jgg@ziepe.ca \
    --cc=jonathan.cameron@huawei.com \
    --cc=kys@microsoft.com \
    --cc=leon@kernel.org \
    --cc=linux-alpha@vger.kernel.org \
    --cc=linux-cxl@vger.kernel.org \
    --cc=linux-hyperv@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=logang@deltatee.com \
    --cc=martin.petersen@oracle.com \
    --cc=mattst88@gmail.com \
    --cc=miquel.raynal@bootlin.com \
    --cc=mwalle@kernel.org \
    --cc=naveenkrishna.chatradhi@amd.com \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=pratyush@kernel.org \
    --cc=rafael@kernel.org \
    --cc=richard.henderson@linaro.org \
    --cc=richard@nod.at \
    --cc=simona@ffwll.ch \
    --cc=srinivas.kandagatla@linaro.org \
    --cc=tudor.ambarus@linaro.org \
    --cc=vigneshr@ti.com \
    --cc=vishal.l.verma@intel.com \
    --cc=wei.liu@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox