Skip to contentSkip to conversation

Is there any way to add an attribute under sysfs at the “platform” level?

DISCUSSION Roman Storozhenko 2 participants 4 messages Jun 18, 2017 – Jun 19, 2017

lore
Share & tools
lore
#0 lore raw

Hello everybody!

I am trying to modify "pcspkr" driver undere linux kernel source tree. I added a new line there:

sample_id_dir = kobject_create_and_add("devices/platform/pcspkr/sample", NULL);

It works and creates kobject without errors. I checked this in the driver code and in the dmesg output. But "sample" catalog isn't appear under "/sys/devices/platform/pcspkr/".

What is wrong with that code ?

Thanks in advance,
Roman Storozhenko

#1 lore raw
Quoted 5 lines · Roman Storozhenko

Hello everybody!

I am trying to modify "pcspkr" driver undere linux kernel source tree. I added a new line there:

sample_id_dir = kobject_create_and_add("devices/platform/pcspkr/sample", NULL);

Ick, really? What are you trying to do with "raw" kobjects?

Quoted 1 line

It works and creates kobject without errors. I checked this in the driver code and in the dmesg output. But "sample" catalog isn't appear under "/sys/devices/platform/pcspkr/".

Are you sure? Odds are you really did create a kobject with that name, but note, the name will have '/' characters in it :)

If you want a kobject in a specific directory, you have to give it the parent kobject directory directly, you can not give a "path" to the kobject name, sorry, that's not how it works.

The kobject documentation should help you out here, have you read it?

good luck!

greg k-h

#2 lore raw
Quoted 8 lines · Greg KH
Quoted 5 lines · Roman Storozhenko

Hello everybody!

I am trying to modify "pcspkr" driver undere linux kernel source tree. I added a new line there:

sample_id_dir = kobject_create_and_add("devices/platform/pcspkr/sample", NULL);

Ick, really? What are you trying to do with "raw" kobjects?

I am trying to add "read/write" attribute under
"devices/platform/pcspkr". Just for educational purposes. Didn't find another way to do it.

Quoted 6 lines
Quoted 2 lines

It works and creates kobject without errors. I checked this in the driver code and in the dmesg output. But "sample" catalog isn't appear under "/sys/devices/platform/pcspkr/".

Are you sure? Odds are you really did create a kobject with that name, but note, the name will have '/' characters in it :)

Quoted 7 lines

If you want a kobject in a specific directory, you have to give it the parent kobject directory directly, you can not give a "path" to the kobject name, sorry, that's not how it works.

The kobject documentation should help you out here, have you read it?

good luck!

I have read documentation about sysfs and kobject. Now I am going to re-read it again.

Thanks, Greg.

Quoted 2 lines

greg k-h

#3 lore raw
Quoted 4 lines · Roman Storozhenko
Quoted 3 lines · Greg KH
Quoted 2 lines · Roman Storozhenko

Hello everybody!

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

I am trying to modify "pcspkr" driver undere linux kernel source tree. I added a new line there:

sample_id_dir = kobject_create_and_add("devices/platform/pcspkr/sample", NULL);

Ick, really? What are you trying to do with "raw" kobjects?

I am trying to add "read/write" attribute under
"devices/platform/pcspkr". Just for educational purposes. Didn't find another way to do it.

Using a kobject is not how to do that at all, attributes need to be added to the structure that owns the directory. kobjects are a directory themselves.

good luck!

greg k-h