All of lore.kernel.org
 help / color / mirror / Atom feed
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, "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: Thu, 25 Aug 2016 08:49:48 -0400	[thread overview]
Message-ID: <20160825124948.GA15567@kroah.com> (raw)
In-Reply-To: <20160825080546.27182-1-zajec5@gmail.com>

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...)

> +	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?

> +
> +	/* 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"?


> +
> +	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?

thanks,

greg k-h

  reply	other threads:[~2016-08-25 12:56 UTC|newest]

Thread overview: 23+ 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  8:03 ` Rafał Miłecki
2016-08-25 12:49 ` Greg KH [this message]
2016-08-26 15:38   ` Rafał Miłecki
2016-08-30 12:05     ` Greg KH
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-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=20160825124948.GA15567@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.