From: Greg KH <gregkh@linuxfoundation.org>
To: "Rafał Miłecki" <zajec5@gmail.com>
Cc: "Richard Purdie" <rpurdie@rpsys.net>,
"Jacek Anaszewski" <j.anaszewski@samsung.com>,
"Felipe Balbi" <balbi@kernel.org>,
"Peter Chen" <hzpeterchen@gmail.com>,
"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
"Rafał Miłecki" <rafal@milecki.pl>,
"Jonathan Corbet" <corbet@lwn.net>,
"Ezequiel Garcia" <ezequiel@vanguardiasur.com.ar>,
"Boris Brezillon" <boris.brezillon@free-electrons.com>,
"Geert Uytterhoeven" <geert@linux-m68k.org>,
"Stephan Linz" <linz@li-pro.net>,
"open list" <linux-kernel@vger.kernel.org>,
"open list:DOCUMENTATION" <linux-doc@vger.kernel.org>,
"open list:LED SUBSYSTEM" <linux-leds@vger.kernel.org>
Subject: Re: [PATCH V4] leds: trigger: Introduce an USB port trigger
Date: Tue, 30 Aug 2016 14:05:56 +0200 [thread overview]
Message-ID: <20160830120556.GA24151@kroah.com> (raw)
In-Reply-To: <CACna6ryGYu_1EUPTSjhuaLnd=ANnjdCXHb1FXaz9P0J87vmRDA@mail.gmail.com>
On Fri, Aug 26, 2016 at 05:38:05PM +0200, Rafał Miłecki wrote:
> On 25 August 2016 at 14:49, Greg KH <gregkh@linuxfoundation.org> wrote:
> > On Thu, Aug 25, 2016 at 10:03:52AM +0200, Rafał Miłecki wrote:
> >> +static void usbport_trig_activate(struct led_classdev *led_cdev)
> >> +{
> >> + struct usbport_trig_data *usbport_data;
> >> + int err;
> >> +
> >> + usbport_data = kzalloc(sizeof(*usbport_data), GFP_KERNEL);
> >> + if (!usbport_data)
> >> + return;
> >> + usbport_data->led_cdev = led_cdev;
> >> +
> >> + /* Storing ports */
> >> + INIT_LIST_HEAD(&usbport_data->ports);
> >> + usbport_data->ports_dir = kobject_create_and_add("ports",
> >> + &led_cdev->dev->kobj);
> >
> > If you _ever_ find yourself in a driver having to use kobject calls,
> > it's a HUGE hint that you are doing something wrong.
> >
> > Hint, you are doing this wrong :)
> >
> > Use an attribute group if you need a subdirectory in sysfs, using a
> > "raw" kobject like this hides it from all userspace tools and so no
> > userspace program can see it (hint, try using libudev to access these
> > files attached to the device...)
>
> Oops. Thanks for pointing groups to me. I was looking at sysfs.h
> earlier but I didn't realize group can be a subdirectory. I can see
> these sysfs_create_group(s) and friends now, thanks.
No, use an attribute group, and name it, and the subdir will be created
automagically for you.
> >> + if (!usbport_data->ports_dir)
> >> + goto err_free;
> >> +
> >> + /* API for ports management */
> >> + err = device_create_file(led_cdev->dev, &dev_attr_new_port);
> >> + if (err)
> >> + goto err_put_ports;
> >> + err = device_create_file(led_cdev->dev, &dev_attr_remove_port);
> >> + if (err)
> >> + goto err_remove_new_port;
> >
> > Doesn't this race with userspace and fail? Shouldn't the led core be
> > creating your leds for you?
>
> These questions aren't clear to me. What kind of race? Doing
> echo usbport > trigger
> results in trigger core calling usbport_trig_activate. We create new
> attributes and then we return.
Why aren't the attributes present when the device is found? What is
"trigger" for?
> I'm also not creating any leds there. This already has to be LED
> available if you want to assign some trigger to it.
That sounds really odd...
> >> +
> >> + /* Notifications */
> >> + usbport_data->nb.notifier_call = usbport_trig_notify,
> >> + led_cdev->trigger_data = usbport_data;
> >> + usb_register_notify(&usbport_data->nb);
> >
> > Don't abuse the USB notifier chain with stuff like this please, is that
> > really necessary? Why can't your hardware just tell you what USB ports
> > are in use "out of band"?
>
> I totally don't understand this part. This LED trigger is supposed to
> react to USB devices appearing at specified ports. How else can I know
> there is a new USB device if not by notifications?
> I'm wondering if we are on the same page. Could it be my idea of this
> LED trigger is not clear at all? Could you take a look at commit
> message again, please? Mostly this part:
> > This commit adds a new trigger responsible for turning on LED when USB
> > device gets connected to the specified USB port. This can can useful for
> > various home routers that have USB port(s) and a proper LED telling user
> > a device is connected.
>
> Can I add something more to make it clear what this trigger is responsible for?
Yes please, as I totally missed that.
And the USB notifier was created for some "special" parts of the USB
core to use, this feels like an abuse of that in some way. But it's
hard to define, I know...
> >> +
> >> + led_cdev->activated = true;
> >> + return;
> >> +
> >> +err_remove_new_port:
> >> + device_remove_file(led_cdev->dev, &dev_attr_new_port);
> >> +err_put_ports:
> >> + kobject_put(usbport_data->ports_dir);
> >> +err_free:
> >> + kfree(usbport_data);
> >> +}
> >
> > And again, why is this USB specific? Why can't you use this same
> > userspace api and codebase for PCI ports? For a sdcard port? For a
> > thunderbolt port?
>
> I'm leaving this one unanswered as discussion on this continued in
> V3.5 thread below my reply:
> On 25 August 2016 at 07:14, Rafał Miłecki <zajec5@gmail.com> wrote:
> > Good question. I would like to extend this USB port trigger in the
> > future by reacting to USB activity. This involves playing with URBs
> > and I believe that at that point it'd be getting too much USB specific
> > to /rule them all/.
No, I mean why not have this specific activity LED work for all types of
devices, not just USB.
Not that this specific LED works for other types of USB activity.
thanks,
greg k-h
next prev parent reply other threads:[~2016-08-30 12:05 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-25 8:03 [PATCH V4] leds: trigger: Introduce an USB port trigger Rafał Miłecki
2016-08-25 12:49 ` Greg KH
2016-08-26 15:38 ` Rafał Miłecki
2016-08-30 12:05 ` Greg KH [this message]
2016-08-30 20:28 ` Rafał Miłecki
2016-08-30 20:54 ` Alan Stern
2016-08-30 21:14 ` Rafał Miłecki
2016-08-31 18:23 ` Alan Stern
2016-08-31 19:00 ` Rafał Miłecki
2016-09-01 5:25 ` Rafał Miłecki
2016-09-01 7:26 ` Jacek Anaszewski
2016-09-01 14:36 ` Alan Stern
2016-09-02 6:54 ` Jacek Anaszewski
[not found] ` <caccb909-bf51-8f67-cd57-de407e576afc-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2016-09-02 14:33 ` Alan Stern
2016-09-03 15:06 ` Jacek Anaszewski
2016-09-03 15:17 ` Alan Stern
2016-09-03 19:12 ` Jacek Anaszewski
2016-09-04 0:24 ` Alan Stern
2016-09-05 9:28 ` Rafał Miłecki
2016-10-10 14:25 ` Pavel Machek
2016-10-10 14:25 ` Pavel Machek
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=20160830120556.GA24151@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=balbi@kernel.org \
--cc=boris.brezillon@free-electrons.com \
--cc=corbet@lwn.net \
--cc=ezequiel@vanguardiasur.com.ar \
--cc=geert@linux-m68k.org \
--cc=hzpeterchen@gmail.com \
--cc=j.anaszewski@samsung.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=linz@li-pro.net \
--cc=rafal@milecki.pl \
--cc=rpurdie@rpsys.net \
--cc=zajec5@gmail.com \
/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;
as well as URLs for NNTP newsgroup(s).