Re: [PATCH][DRIVER][RFC] CPU5 watchdog driver for 2.5

From: Heiko Ronsdorf (sk048ro@crimson.ihg.uni-duisburg.de)
Date: Wed Feb 12 2003 - 11:25:25 EST


> Here is your cpu5wdt.c file with the procfs stuff replaced with code
> that adds an embedded platform_device to your basic data structure,
> registers the driver as a platform device, and then creates a file
> called $YOUR_SYSFS_ROOT/devices/legacy/watchdog0/statistics that will
> read the same as your original procfs file. (Or at least I think it
> will. It at least compiles :->)

>From Documentation/filesystems/sysfs.txt

"Mixing types, expressing mulitple lines of data, and doing fancy
formatting of data is heavily frowned upon. Doing these things may get
you publically humiliated and your code rewritten without notice."

Luckily it wasn't my suggestion. :-)

Well, in the right manner to use sysfs I have to create a file for
each (4) of the variables. So I have to write 4 (!) functions for
reading my vars, and all look similar. :-( This is over-designed for
no (real) functionality in only one driver, I guess. Only two or three
of the other watchdog drivers provide a "read" on some data, so no
code can shared between them.

There should be some functions/MACROS in sysfs to declare a read/write
operation on an single int/long etc.. Something like:

struct attribute {
        char * name;
        mode_t mode;
        void * data;
};

struct device_attribute {
        struct attribute attr;
        ssize_t (*show)(struct device * dev, char * buf, void * data);
        ssize_t (*store)(struct device * dev, const char * buf, \
                        size_t count, void * data);
};

#define DEVICE_INT_ATTR(_name,_str,_mode,_var) \
struct device_attribute dev_attr_##_name = { \
        .attr = {.name = __stringify(_name), .mode = _mode, .data = &var }, \
        .show = _default_int_show, \
        .store = _default_int_store, \
};

size_t _default_int_show(struct device *dev, char *buf, void *data) {
        return sprintf("%i\n", *(int *)data);
}

static ssize_t
subsys_attr_show(struct kobject * kobj, struct attribute * attr, char * page)
{
        struct subsystem * s = to_subsys(kobj);
        struct subsys_attribute * sattr = to_sattr(attr);
        ssize_t ret = 0;

        if (sattr->show)
                ret = sattr->show(s,page,attr->data);
        return ret;
}

With these [IMHO] it would be easier to make use of sysfs.

Finally, I've decided to remove the procfs code (and keep a patch for
myself) from the watchdog driver.

Heiko

--
Sorry for my denglisch


- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Sat Feb 15 2003 - 22:00:43 EST