linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Matthias Kaehlcke <mka@chromium.org>
Cc: Rob Herring <robh+dt@kernel.org>,
	Frank Rowand <frowand.list@gmail.com>,
	devicetree@vger.kernel.org, Peter Chen <peter.chen@nxp.com>,
	Stephen Boyd <swboyd@chromium.org>,
	Alan Stern <stern@rowland.harvard.edu>,
	Ravi Chandra Sadineni <ravisadineni@chromium.org>,
	Bastien Nocera <hadess@hadess.net>,
	linux-kernel@vger.kernel.org,
	Douglas Anderson <dianders@chromium.org>,
	linux-usb@vger.kernel.org, Krzysztof Kozlowski <krzk@kernel.org>,
	Al Cooper <alcooperx@gmail.com>,
	"Alexander A. Klimov" <grandmaster@al2klimov.de>,
	Masahiro Yamada <masahiroy@kernel.org>
Subject: Re: [PATCH v5 2/4] USB: misc: Add onboard_usb_hub driver
Date: Thu, 11 Feb 2021 08:03:01 +0100	[thread overview]
Message-ID: <YCTWpUqD7vSu0c4k@kroah.com> (raw)
In-Reply-To: <20210210091015.v5.2.I7c9a1f1d6ced41dd8310e8a03da666a32364e790@changeid>

On Wed, Feb 10, 2021 at 09:10:37AM -0800, Matthias Kaehlcke wrote:
> +static int onboard_hub_add_usbdev(struct onboard_hub *hub, struct usb_device *udev)
> +{
> +	struct udev_node *node;
> +	char link_name[64];
> +	int ret = 0;
> +
> +	mutex_lock(&hub->lock);
> +
> +	if (hub->going_away) {
> +		ret = -EINVAL;
> +		goto unlock;
> +	}
> +
> +	node = devm_kzalloc(hub->dev, sizeof(*node), GFP_KERNEL);
> +	if (!node) {
> +		ret = -ENOMEM;
> +		goto unlock;
> +	}
> +
> +	node->udev = udev;
> +
> +	list_add(&node->list, &hub->udev_list);
> +
> +	snprintf(link_name, sizeof(link_name), "usb_dev.%s", dev_name(&udev->dev));
> +	WARN_ON(sysfs_create_link(&hub->dev->kobj, &udev->dev.kobj, link_name));

Never use WARN_ON() unless you want the machine to reboot if it triggers
(panic on warn).

But the larger question is what is this sysfs link for?  It's not
documented anywhere, and so, shouldn't be allowed.  Who is going to use
it and why is it needed?



> +
> +unlock:
> +	mutex_unlock(&hub->lock);
> +
> +	return ret;
> +}
> +
> +static void onboard_hub_remove_usbdev(struct onboard_hub *hub, struct usb_device *udev)
> +{
> +	struct udev_node *node;
> +	char link_name[64];
> +
> +	snprintf(link_name, sizeof(link_name), "usb_dev.%s", dev_name(&udev->dev));
> +	sysfs_remove_link(&hub->dev->kobj, link_name);
> +
> +	mutex_lock(&hub->lock);
> +
> +	list_for_each_entry(node, &hub->udev_list, list) {
> +		if (node->udev == udev) {
> +			list_del(&node->list);
> +			break;
> +		}
> +	}
> +
> +	mutex_unlock(&hub->lock);
> +}
> +
> +static ssize_t always_powered_in_suspend_show(struct device *dev, struct device_attribute *attr,
> +			   char *buf)
> +{
> +	struct onboard_hub *hub = dev_get_drvdata(dev);
> +
> +	return sprintf(buf, "%d\n", hub->always_powered_in_suspend);

sysfs_emit()?

And you forgot the Documentation/ABI/ entries for this driver, so it
really can not be reviewed...


> +}
> +
> +static ssize_t always_powered_in_suspend_store(struct device *dev, struct device_attribute *attr,
> +			    const char *buf, size_t count)
> +{
> +	struct onboard_hub *hub = dev_get_drvdata(dev);
> +	bool val;
> +	int ret;
> +
> +	ret = kstrtobool(buf, &val);
> +	if (ret < 0)
> +		return ret;
> +
> +	hub->always_powered_in_suspend = val;
> +
> +	return count;
> +}
> +static DEVICE_ATTR_RW(always_powered_in_suspend);
> +
> +static struct attribute *onboard_hub_sysfs_entries[] = {
> +	&dev_attr_always_powered_in_suspend.attr,
> +	NULL,
> +};
> +
> +static const struct attribute_group onboard_hub_sysfs_group = {
> +	.attrs = onboard_hub_sysfs_entries,
> +};
> +
> +static int onboard_hub_probe(struct platform_device *pdev)
> +{
> +	struct device *dev = &pdev->dev;
> +	struct onboard_hub *hub;
> +	int err;
> +
> +	hub = devm_kzalloc(dev, sizeof(*hub), GFP_KERNEL);
> +	if (!hub)
> +		return -ENOMEM;
> +
> +	hub->vdd = devm_regulator_get(dev, "vdd");
> +	if (IS_ERR(hub->vdd))
> +		return PTR_ERR(hub->vdd);
> +
> +	hub->dev = dev;
> +	mutex_init(&hub->lock);
> +	INIT_LIST_HEAD(&hub->udev_list);
> +
> +	dev_set_drvdata(dev, hub);
> +
> +	err = devm_device_add_group(dev, &onboard_hub_sysfs_group);

You just raced userspace and lost :(

Please use the correct api to add sysfs attributes to the device
automatically by the driver core.  But the larger question is why do you
need them at all?  What do they do that we can't already do with
existing apis that you feel a one-off api for this driver is required?



> +	if (err) {
> +		dev_err(dev, "failed to create sysfs entries: %d\n", err);
> +		return err;
> +	}
> +
> +	err = onboard_hub_power_on(hub);
> +	if (err)
> +		return err;
> +
> +	/*
> +	 * The USB driver might have been detached from the USB devices by
> +	 * onboard_hub_remove() make sure to re-attach it if needed.
> +	 */
> +	(void)driver_attach(&onboard_hub_usbdev_driver.drvwrap.driver);

(void)????

Please no, do it right.

But, why is a driver calling this function anyway?  That feels really
really wrong...

thanks,

greg k-h

  reply	other threads:[~2021-02-11  7:03 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-10 17:10 [PATCH v5 0/4] USB: misc: Add onboard_usb_hub driver Matthias Kaehlcke
2021-02-10 17:10 ` [PATCH v5 1/4] dt-bindings: usb: Add binding for discrete onboard USB hubs Matthias Kaehlcke
2021-02-11 14:56   ` Rob Herring
2021-02-17 21:04   ` Rob Herring
2021-02-18  1:33     ` Matthias Kaehlcke
2021-02-19 15:05       ` Rob Herring
2021-02-22 17:39         ` Matthias Kaehlcke
2021-02-10 17:10 ` [PATCH v5 2/4] USB: misc: Add onboard_usb_hub driver Matthias Kaehlcke
2021-02-11  7:03   ` Greg Kroah-Hartman [this message]
2021-02-11 18:04     ` Matthias Kaehlcke
2021-02-10 17:10 ` [PATCH v5 3/4] usb: host: xhci-plat: Create platform device for onboard hubs in probe() Matthias Kaehlcke
2021-02-10 21:06   ` Krzysztof Kozlowski
2021-02-10 22:20     ` Matthias Kaehlcke
2021-02-11 19:14       ` Stephen Boyd
2021-02-11 20:36         ` Matthias Kaehlcke
2021-02-11 20:45           ` Stephen Boyd
2021-02-11 22:46             ` Rob Herring
2021-02-11 22:40         ` Rob Herring
2021-02-11  6:58   ` Greg Kroah-Hartman
2021-02-11 18:45     ` Matthias Kaehlcke
2021-02-11 19:01       ` Matthias Kaehlcke
2021-02-10 17:10 ` [PATCH v5 4/4] arm64: dts: qcom: sc7180-trogdor: Add nodes for onboard USB hub Matthias Kaehlcke
2021-02-10 21:04 ` [PATCH v5 0/4] USB: misc: Add onboard_usb_hub driver Krzysztof Kozlowski
2021-02-10 22:37   ` Matthias Kaehlcke
2021-02-24 13:25 ` Michal Simek

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=YCTWpUqD7vSu0c4k@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=alcooperx@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dianders@chromium.org \
    --cc=frowand.list@gmail.com \
    --cc=grandmaster@al2klimov.de \
    --cc=hadess@hadess.net \
    --cc=krzk@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=masahiroy@kernel.org \
    --cc=mka@chromium.org \
    --cc=peter.chen@nxp.com \
    --cc=ravisadineni@chromium.org \
    --cc=robh+dt@kernel.org \
    --cc=stern@rowland.harvard.edu \
    --cc=swboyd@chromium.org \
    /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).