Re: invalid drv data in show attribute

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

 



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...

> 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?

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