Re: [PATCH 2/2] treewide: Use sysfs_bin_attr_simple_read() helper

From: Greg Kroah-Hartman
Date: Thu May 23 2024 - 02:52:01 EST


On Wed, May 22, 2024 at 07:51:35PM -0700, Guenter Roeck wrote:
> Hi,
>
> On Sat, Apr 06, 2024 at 03:52:02PM +0200, Lukas Wunner wrote:
> > Deduplicate ->read() callbacks of bin_attributes which are backed by a
> > simple buffer in memory:
> >
> > Use the newly introduced sysfs_bin_attr_simple_read() helper instead,
> > either by referencing it directly or by declaring such bin_attributes
> > with BIN_ATTR_SIMPLE_RO() or BIN_ATTR_SIMPLE_ADMIN_RO().
> >
> > Aside from a reduction of LoC, this shaves off a few bytes from vmlinux
> > (304 bytes on an x86_64 allyesconfig).
> >
> > No functional change intended.
> >
>
> Not really; see below.
>
> > Signed-off-by: Lukas Wunner <lukas@xxxxxxxxx>
> > Acked-by: Michael Ellerman <mpe@xxxxxxxxxxxxxx> (powerpc)
> > ---
> ...
> > index da79760..5193fae 100644
> > --- a/init/initramfs.c
> > +++ b/init/initramfs.c
> > @@ -575,15 +575,7 @@ static int __init initramfs_async_setup(char *str)
> > #include <linux/initrd.h>
> > #include <linux/kexec.h>
> >
> > -static ssize_t raw_read(struct file *file, struct kobject *kobj,
> > - struct bin_attribute *attr, char *buf,
> > - loff_t pos, size_t count)
> > -{
> > - memcpy(buf, attr->private + pos, count);
> > - return count;
> > -}
> > -
> > -static BIN_ATTR(initrd, 0440, raw_read, NULL, 0);
> > +static BIN_ATTR(initrd, 0440, sysfs_bin_attr_simple_read, NULL, 0);
> >
>
> sysfs_bin_attr_simple_read is only declared and available if CONFIG_SYSFS=y.
> With m68k:m5208evb_defconfig + CONFIG_BLK_DEV_INITRD=y, this results in
>
> /opt/buildbot/slave/qemu-m68k/build/init/initramfs.c:578:31:
> error: 'sysfs_bin_attr_simple_read' undeclared here (not in a function)
>
> This happens because CONFIG_SYSFS=n and there is no dummy function for
> sysfs_bin_attr_simple_read(). Presumably the problem will be seen for all
> configurations with CONFIG_BLK_DEV_INITRD=y and CONFIG_SYSFS=n.

Lukas, can you send a patch adding a dummy function?

thanks,

greg k-h