From: Greg KH <gregkh@linuxfoundation.org>
To: "Czerwacki, Eial" <eial.czerwacki@sap.com>
Cc: "linux-staging@lists.linux.dev" <linux-staging@lists.linux.dev>,
"Hammer, Gal" <gal.hammer@sap.com>
Subject: Re: invalid drv data in show attribute
Date: Mon, 5 Sep 2022 07:49:32 +0200 [thread overview]
Message-ID: <YxWN7Fm07segTeqU@kroah.com> (raw)
In-Reply-To: <PAXPR02MB7310E14184AA4389841AE89E817C9@PAXPR02MB7310.eurprd02.prod.outlook.com>
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
next prev parent reply other threads:[~2022-09-05 5:49 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-04 14:37 invalid drv data in show attribute Czerwacki, Eial
2022-09-05 5:49 ` Greg KH [this message]
2022-09-05 6:07 ` Czerwacki, Eial
2022-09-05 7:01 ` Greg KH
2022-09-05 7:28 ` Czerwacki, Eial
2022-09-05 11:41 ` Greg KH
2022-09-05 12:02 ` Czerwacki, Eial
2022-09-05 12:10 ` Greg KH
2022-09-05 12:56 ` Czerwacki, Eial
2022-09-05 15:12 ` Greg KH
2022-09-05 15:52 ` Czerwacki, Eial
2022-09-05 16:02 ` Greg KH
2022-09-06 7:30 ` Czerwacki, Eial
2022-09-06 12:09 ` Greg KH
2022-09-06 12:28 ` Czerwacki, Eial
2022-09-05 7:07 ` Greg KH
2022-09-05 7:44 ` Czerwacki, Eial
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=YxWN7Fm07segTeqU@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=eial.czerwacki@sap.com \
--cc=gal.hammer@sap.com \
--cc=linux-staging@lists.linux.dev \
/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