Using binary attributes for configuration sysfs entries

valdis.kletnieks at vt.edu valdis.kletnieks at vt.edu
Wed Mar 13 02:56:47 EDT 2019


On Wed, 13 Mar 2019 12:02:02 +0530, Jay Aurabind said:

> For the corresponding sysfs interface, since there are a lot of
> parameters, would it be justified to use the same binary format though
> sysfs_create_binary_file() ? The rationale is that it would be easier
> to simply pack all the config options in the struct and send it in
> once rather than individually write 40 files. This is what the
> attached patch follows. Interface is added only for reception
> parameters as of now.

Sysfs has a rule of "one value per file" - and saying "the one value is the
config struct we read/write to the file" is stretching that quite a bit.   By
the time you're doing all the marshaling of values in and out of this struct,
there's no real benefit to do it via sysfs rather than the existing ioctl()
call.

Make sure you double-check that "the same binary format" means what you
think it does when considering 32/64 bit architectures. While you're there, double
check that the ioctl() works correctly for a 32-bit userspace program running
on a 64-bit kernel - we have historically had an incredible number of API botches
for that case.

Of course, it helps your case considerably if you can point at something else
in sysfs and say "The Foobar 9934 driver already does this".. :)

On the other hand, having 40 files is just a massive race condition waiting to
happen, especially if the device has hardware weirdness that imply that certain
sets of (say) 3 or 5 parameters have to be changed in unison.




More information about the Kernelnewbies mailing list