All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 8/8] Input: usbtouchscreen - switch to using __free() cleanup facility
Date: Fri, 12 Jul 2024 09:27:00 +0200	[thread overview]
Message-ID: <2024071246-moaning-galore-7830@gregkh> (raw)
In-Reply-To: <20240712051851.3463657-8-dmitry.torokhov@gmail.com>

On Thu, Jul 11, 2024 at 10:18:50PM -0700, Dmitry Torokhov wrote:
> Use __free(kfree) cleanup facility when allocating temporary buffers
> for USB transfers.
> 
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> ---
>  drivers/input/touchscreen/usbtouchscreen.c | 90 ++++++++--------------
>  1 file changed, 33 insertions(+), 57 deletions(-)
> 
> diff --git a/drivers/input/touchscreen/usbtouchscreen.c b/drivers/input/touchscreen/usbtouchscreen.c
> index 0015f0a6de01..7567efabe014 100644
> --- a/drivers/input/touchscreen/usbtouchscreen.c
> +++ b/drivers/input/touchscreen/usbtouchscreen.c
> @@ -167,9 +167,8 @@ static const struct usbtouch_device_info e2i_dev_info = {
>  
>  static int egalax_init(struct usbtouch_usb *usbtouch)
>  {
> -	int ret, i;
> -	unsigned char *buf;
>  	struct usb_device *udev = interface_to_usbdev(usbtouch->interface);
> +	int ret, i;
>  
>  	/*
>  	 * An eGalax diagnostic packet kicks the device into using the right
> @@ -177,7 +176,7 @@ static int egalax_init(struct usbtouch_usb *usbtouch)
>  	 * read later and ignored.
>  	 */
>  
> -	buf = kmalloc(3, GFP_KERNEL);
> +	u8 *buf __free(kfree) = kmalloc(3, GFP_KERNEL);
>  	if (!buf)
>  		return -ENOMEM;
>  
> @@ -191,17 +190,11 @@ static int egalax_init(struct usbtouch_usb *usbtouch)
>  				      USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
>  				      0, 0, buf, 3,
>  				      USB_CTRL_SET_TIMEOUT);
> -		if (ret >= 0) {
> -			ret = 0;
> -			break;
> -		}
>  		if (ret != -EPIPE)
>  			break;
>  	}
>  
> -	kfree(buf);
> -
> -	return ret;
> +	return ret < 0 ? ret : 0;

Personally I hate ? : usage, but it's your subsystem and it's used
elsewhere in this file, so you have to live with it :)

>  }
>  
>  static int egalax_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
> @@ -358,10 +351,9 @@ static int mtouch_get_fw_revision(struct usbtouch_usb *usbtouch)
>  {
>  	struct usb_device *udev = interface_to_usbdev(usbtouch->interface);
>  	struct mtouch_priv *priv = usbtouch->priv;
> -	u8 *buf;
>  	int ret;
>  
> -	buf = kzalloc(MTOUCHUSB_REQ_CTRLLR_ID_LEN, GFP_NOIO);
> +	u8 *buf __free(kfree) = kzalloc(MTOUCHUSB_REQ_CTRLLR_ID_LEN, GFP_NOIO);
>  	if (!buf)
>  		return -ENOMEM;
>  
> @@ -373,18 +365,13 @@ static int mtouch_get_fw_revision(struct usbtouch_usb *usbtouch)
>  	if (ret != MTOUCHUSB_REQ_CTRLLR_ID_LEN) {
>  		dev_warn(&usbtouch->interface->dev,
>  			 "Failed to read FW rev: %d\n", ret);
> -		ret = ret < 0 ? ret : -EIO;
> -		goto free;
> +		return ret < 0 ? ret : -EIO;
>  	}
>  
>  	priv->fw_rev_major = buf[3];
>  	priv->fw_rev_minor = buf[4];
>  
> -	ret = 0;
> -
> -free:
> -	kfree(buf);
> -	return ret;
> +	return 0;
>  }
>  
>  static int mtouch_alloc(struct usbtouch_usb *usbtouch)
> @@ -636,24 +623,23 @@ static const struct usbtouch_device_info gunze_dev_info = {
>  static int dmc_tsc10_init(struct usbtouch_usb *usbtouch)
>  {
>  	struct usb_device *dev = interface_to_usbdev(usbtouch->interface);
> -	int ret = -ENOMEM;
> -	unsigned char *buf;
> +	int ret;
>  
> -	buf = kmalloc(2, GFP_NOIO);
> +	u8 *buf __free(kfree) = kmalloc(2, GFP_NOIO);
>  	if (!buf)
> -		goto err_nobuf;
> +		return -ENOMEM;
> +
>  	/* reset */
>  	buf[0] = buf[1] = 0xFF;
>  	ret = usb_control_msg(dev, usb_rcvctrlpipe (dev, 0),
> -	                      TSC10_CMD_RESET,
> -	                      USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
> -	                      0, 0, buf, 2, USB_CTRL_SET_TIMEOUT);
> +			      TSC10_CMD_RESET,
> +			      USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
> +			      0, 0, buf, 2, USB_CTRL_SET_TIMEOUT);

Unintentional whitespace change?

Anyway, not a big deal, cleanup looks good:

Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

  reply	other threads:[~2024-07-12  7:27 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-12  5:18 [PATCH 1/8] Input: usbtouchscreen - use driver core to instantiate device attributes Dmitry Torokhov
2024-07-12  5:18 ` [PATCH 2/8] Input: usbtouchscreen - remove custom USB_DEVICE_HID_CLASS macro Dmitry Torokhov
2024-07-12  7:29   ` Greg KH
2024-07-12  5:18 ` [PATCH 3/8] Input: usbtouchscreen - move the driver ID table Dmitry Torokhov
2024-07-12  7:29   ` Greg KH
2024-07-12  5:18 ` [PATCH 4/8] Input: usbtouchscreen - move process_pkt() into main device structure Dmitry Torokhov
2024-07-12  7:29   ` Greg KH
2024-07-12  5:18 ` [PATCH 5/8] Input: usbtouchscreen - constify usbtouch_dev_info table Dmitry Torokhov
2024-07-12  7:28   ` Greg KH
2024-07-12  5:18 ` [PATCH 6/8] Input: usbtouchscreen - split device info table into individual pieces Dmitry Torokhov
2024-07-12  7:28   ` Greg KH
2024-07-12  5:18 ` [PATCH 7/8] Input: usbtouchscreen - use guard notation when acquiring mutexes Dmitry Torokhov
2024-07-12  7:28   ` Greg KH
2024-07-12  5:18 ` [PATCH 8/8] Input: usbtouchscreen - switch to using __free() cleanup facility Dmitry Torokhov
2024-07-12  7:27   ` Greg KH [this message]
2024-07-12  7:27 ` [PATCH 1/8] Input: usbtouchscreen - use driver core to instantiate device attributes Greg KH

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=2024071246-moaning-galore-7830@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.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 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.