Re: invalid drv data in show attribute

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Sep 05, 2022 at 06:07:07AM +0000, Czerwacki, Eial wrote:
>
> >On Sun, Sep 04, 2022 at 02:37:32PM +0000, Czerwacki, Eial wrote:
> >> Greetings,
> >> 
> >> while working on a driver, I've found a bug that I'm unable to understand.
> >> I assume that I'm doing something wrong. here is my reduced c file:
> >
> ><snip>
> >
> >I'll provide a better review after my coffee, but just one comment
> >first.  Ok, two:
> >
> >> #ifndef sysfs_emit
> >> #define sysfs_emit sprintf
> >> #endif // sysfs_emit
> >
> >Wait what?  You mention at the end that you do nto have sysfs_emit in
> >your kernel tree, but all activly maintained kernels does have this
> >function.  You should NEVER be working on a kernel tree that is not
> >actually supported, and for new code like you are wanting to submit, you
> >should always work on Linus's tree, or the last release, or something
> >newer.
> >
> >Please move to 5.19 now, it will save you so much time later on...
> well, I'm kinda binded to this kernel version buy you are right.

What kernel version does not have sysfs_emit()?

> I'll move to newer kernel.
> I'll worry about backports later

backports are always easier than forward-ports.

> >> static int vsmp_pci_probe(struct pci_dev *pci, const struct pci_device_id *id)
> >> {
> >>        struct data *d;
> >>        int ret_val = 0;
> >> 
> >>        d = devm_kzalloc(&pci->dev, sizeof(*d), GFP_KERNEL);
> >>        if (IS_ERR(d))
> >>                return PTR_ERR(d);
> >> 
> >>        d->pdev = pci;
> >>        pci_set_drvdata(pci, d);
> >>        d->kobj = kobject_create_and_add(ROOT_SYFS_FOLDER, &d->pdev->dev.kobj);
> >
> >This is the issue, no driver should ever be calling any kobject_*() or
> >sysfs_*() calls, unless something went very very wrong.
> >
> >Drivers and devices have their own tree in sysfs, with 'struct device'
> >to use.  You have a device here, use that, don't try to create a whole
> >new sysfs tree somewhere else in the heiarchy which does not reflect the
> >actual device you are using here.
> >
> >You then try to tie a device as a child to a kobject, which breaks the
> >whole logical chain here, and then confuses your callback as you really
> >don't have the device pointer anymore, it's some other random thing.
> >
> >So step back and try to describe first what you want to see in sysfs,
> >and then maybe it will be more obvious as to what you need to do here.
> >
> >Write the Documentation/ABI/ entries first, what do they look like for
> >your new sysfs files?
> 
> I thought that is my issue but wasn't sure.
> what I'm looking for is this tree:
> - vsmp
> -- version
> -- summery
> --- data#1
> ...
> --- data#n
> -- boards
> --- 0
> ---- data#1
> ...
> ---- data#k
> --- 1
> ...
> --- l
> 
> each board has a predefine set of attributes when I need to add another depending on the type.
> also there are shared attributes between summery folder and the boards. that I was able to implement based on the name of the entry

So "boards" are devices, and then you need a bus to manage them.  Are
you sure you need/want all of this?

And what exactly is in the other files?

> that I'd like to see under /sys/hypervisor

/sys/hypervisor probably isn't the place for all of that mess.  You are
going to have devices and a bus and all sorts of other complex things.

Step back and explain exactly what you are trying to export, who will be
using it, and what format you want it in.  This feels like a lot of
stuff that is probably not needed except for debugging.

If this isn't for debugging, it's going to be a lot more complex than
"simple" attributes for a driver, sorry.  You are going to need as I
mention above, to use a bus and other things which feels kind of wrong
as odds are this isn't a bus, right?

> I have no problems using link from the device's path to /sys/hypervisor

Why would you create a link?  Look at what existing hypervisors do in
/sys/hypervisor, there's no links there, only a small set of information
that userspace can use for the Xen code, or a more complex virtual
filesystem that the s390 hypervisor mounts at that location.  No one
creates a symlink under there, why would that be necessary?

But again, stop and think about the information you want to export and
who would be using it.  If you can explain that first, that might make
it easier to point out how to do it best.

thanks,

greg k-h




[Index of Archives]     [Linux Driver Development]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux