Linux Today: Linux News On Internet Time.
Search Linux Today
Linux News Sections:  Developer -  High Performance -  Infrastructure -  IT Management -  Security -  Storage -
Linux Today Navigation
LT Home
Contribute
Contribute
Link to Us
Linux Jobs


Top White Papers

More on LinuxToday


How to Create a sysfs File Correctly

Jul 01, 2013, 10:00 (0 Talkback[s])

One common Linux kernel driver issue that I see all the time is a driver
author attempting to create a sysfs file in their code by doing
something like:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
int my_driver_probe(...)
{
        ...
        retval = device_create_file(my_device, &my_first_attribute);
        if (retval)
                goto error1;
        retval = device_create_file(my_device, &my_second_attribute);
        if (retval)
                goto error2;
        ...
        return 0;
error2:
        device_remove_file(my_device, &my_first_attribute);
error1:
        /* Clean up other things and return an error */
        ...
        return -ENODEV;
}

Complete Story