Re: [PATCH v4] hwmon: add POWER-Z driver

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

On 2023-09-02 18:36:17+0200, Christophe JAILLET wrote:
> Le 02/09/2023 à 09:47, Thomas Weißschuh a écrit :
> > POWER-Z is a series of devices to monitor power characteristics of
> > USB-C connections and display those on a on-device display.
> > Some of the devices, notably KM002C and KM003C, contain an additional
> > port which exposes the measurements via USB.
> > 
> > This is a driver for this monitor port.
> > 
> > It was developed and tested with the KM003C.
> > 
> > Signed-off-by: Thomas Weißschuh <linux-9XfqOkM5JgxKQ7RDE2T8Pw@xxxxxxxxxxxxxxxx>
> > ---
> 
> ...
> 
> > +static int powerz_probe(struct usb_interface *intf,
> > +			const struct usb_device_id *id)
> > +{
> > +	struct powerz_priv *priv;
> > +	struct device *hwmon_dev;
> > +	struct device *parent;
> > +
> > +	parent = &intf->dev;
> > +
> > +	priv = devm_kzalloc(parent, sizeof(*priv), GFP_KERNEL);
> > +	if (!priv)
> > +		return -ENOMEM;
> > +
> > +	priv->urb = usb_alloc_urb(0, GFP_KERNEL);
> > +	if (!priv->urb)
> > +		return -ENOMEM;
> > +	mutex_init(&priv->mutex);
> > +	priv->status = -ETIMEDOUT;
> > +	init_completion(&priv->completion);
> > +
> > +	hwmon_dev =
> > +	    devm_hwmon_device_register_with_info(parent, DRIVER_NAME, priv,
> > +						 &powerz_chip_info, NULL);
> > +	usb_set_intfdata(intf, priv);
> > +
> > +	return PTR_ERR_OR_ZERO(hwmon_dev);
> 
> Hi,
> 
> If 'hwmon_dev' is an PTR_ERR, priv->urb leaks.

Good catch, thanks!


Guenter,

it seems the new hwmon-next with this driver has not yet been pushed to
git.kernel.org, so I can't generate the Fixes tag.

Can you modify the commit to also contain the changes below?
Or let me know if you prefer something else.

diff --git a/drivers/hwmon/powerz.c b/drivers/hwmon/powerz.c
index 611d04fb28db..aad585306f80 100644
--- a/drivers/hwmon/powerz.c
+++ b/drivers/hwmon/powerz.c
@@ -233,9 +233,14 @@ static int powerz_probe(struct usb_interface *intf,
 	hwmon_dev =
 	    devm_hwmon_device_register_with_info(parent, DRIVER_NAME, priv,
 						 &powerz_chip_info, NULL);
+	if (IS_ERR(hwmon_dev)) {
+		usb_free_urb(priv->urb);
+		return PTR_ERR(hwmon_dev);
+	}
+
 	usb_set_intfdata(intf, priv);
 
-	return PTR_ERR_OR_ZERO(hwmon_dev);
+	return 0;
 }
 
 static void powerz_disconnect(struct usb_interface *intf)



[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux