On Mon, Jul 29, 2019 at 07:43:09PM -0700, Tri Vo wrote:
> Userspace can use wakeup_sources debugfs node to plot history of suspend
> blocking wakeup sources over device's boot cycle. This information can
> then be used (1) for power-specific bug reporting and (2) towards
> attributing battery consumption to specific processes over a period of
> time.
> 
> However, debugfs doesn't have stable ABI. For this reason, create a
> 'struct device' to expose wakeup sources statistics in sysfs under
> /sys/class/wakeup/wakeup<ID>/*.

I agree with Rafael here, no need for the extra "wakeup" in the device
name as you are in the "wakeup" namespace already.

If you have an IDA-allocated name, there's no need for the extra
'wakeup' at all.

> +int wakeup_source_sysfs_add(struct device *parent, struct wakeup_source *ws)
> +{
> +     struct device *dev;
> +     int id;
> +
> +     id = ida_simple_get(&wakeup_ida, 0, 0, GFP_KERNEL);
> +     if (id < 0)
> +             return id;

No lock needed for this ida?  Are you sure?

> +     ws->id = id;
> +
> +     dev = device_create_with_groups(wakeup_class, parent, MKDEV(0, 0), ws,
> +                                     wakeup_source_groups, "wakeup%d",
> +                                     ws->id);
> +     if (IS_ERR(dev)) {
> +             ida_simple_remove(&wakeup_ida, ws->id);
> +             return PTR_ERR(dev);
> +     }
> +
> +     ws->dev = dev;
> +     return 0;
> +}
> +EXPORT_SYMBOL_GPL(wakeup_source_sysfs_add);
> +
> +/**
> + * wakeup_source_sysfs_remove - Remove wakeup_source attributes from sysfs.
> + * @ws: Wakeup source to be removed from sysfs.
> + */
> +void wakeup_source_sysfs_remove(struct wakeup_source *ws)
> +{
> +     device_unregister(ws->dev);
> +     ida_simple_remove(&wakeup_ida, ws->id);

Again, no lock, is that ok?  I think ida's can work without a lock, but
not always, sorry, I don't remember the rules anymore given the recent
changes in that code.

thanks,

greg k-h

Reply via email to