mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hans de Goede <hdegoede@redhat.com>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>, linux-input@vger.kernel.org
Cc: linux-kernel@vger.kernel.org,
	Benjamin Tissoires <benjamin.tissoires@redhat.com>
Subject: Re: [PATCH] Input: matrix-keymap - switch to using __free() cleanup facility
Date: Sun, 25 Aug 2024 15:13:56 +0200	[thread overview]
Message-ID: <34c641d3-ee4e-4e93-ad42-90a33c0f8b0a@redhat.com> (raw)
In-Reply-To: <ZspoEPdTcH-hpciy@google.com>

Hi,

On 8/25/24 1:09 AM, Dmitry Torokhov wrote:
> Use __free(kfree) cleanup facility in matrix_keypad_parse_keymap() to
> automatically free temporarily allocated memory.
> 
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

Thanks, patch looks good to me:

Reviewed-by: Hans de Goede <hdegoede@redhat.com>

Regards,

Hans



> ---
>  drivers/input/matrix-keymap.c | 25 +++++++++----------------
>  1 file changed, 9 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/input/matrix-keymap.c b/drivers/input/matrix-keymap.c
> index 5d93043bad8e..3bea3575a0a9 100644
> --- a/drivers/input/matrix-keymap.c
> +++ b/drivers/input/matrix-keymap.c
> @@ -73,10 +73,9 @@ static int matrix_keypad_parse_keymap(const char *propname,
>  	struct device *dev = input_dev->dev.parent;
>  	unsigned int row_shift = get_count_order(cols);
>  	unsigned int max_keys = rows << row_shift;
> -	u32 *keys;
>  	int i;
>  	int size;
> -	int retval;
> +	int error;
>  
>  	if (!propname)
>  		propname = "linux,keymap";
> @@ -94,30 +93,24 @@ static int matrix_keypad_parse_keymap(const char *propname,
>  		return -EINVAL;
>  	}
>  
> -	keys = kmalloc_array(size, sizeof(u32), GFP_KERNEL);
> +	u32 *keys __free(kfree) = kmalloc_array(size, sizeof(*keys), GFP_KERNEL);
>  	if (!keys)
>  		return -ENOMEM;
>  
> -	retval = device_property_read_u32_array(dev, propname, keys, size);
> -	if (retval) {
> +	error = device_property_read_u32_array(dev, propname, keys, size);
> +	if (error) {
>  		dev_err(dev, "failed to read %s property: %d\n",
> -			propname, retval);
> -		goto out;
> +			propname, error);
> +		return error;
>  	}
>  
>  	for (i = 0; i < size; i++) {
>  		if (!matrix_keypad_map_key(input_dev, rows, cols,
> -					   row_shift, keys[i])) {
> -			retval = -EINVAL;
> -			goto out;
> -		}
> +					   row_shift, keys[i]))
> +			return -EINVAL;
>  	}
>  
> -	retval = 0;
> -
> -out:
> -	kfree(keys);
> -	return retval;
> +	return 0;
>  }
>  
>  /**


      reply	other threads:[~2024-08-25 13:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-24 23:09 Dmitry Torokhov
2024-08-25 13:13 ` Hans de Goede [this message]

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=34c641d3-ee4e-4e93-ad42-90a33c0f8b0a@redhat.com \
    --to=hdegoede@redhat.com \
    --cc=benjamin.tissoires@redhat.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®