mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Pengpeng Hou <pengpeng@iscas.ac.cn>
Cc: arnd@arndb.de, James.Bottomley@hansenpartnership.com,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] enclosure: bound sysfs link name construction
Date: Sun, 29 Mar 2026 08:13:30 +0200	[thread overview]
Message-ID: <2026032951-surely-molar-7b7a@gregkh> (raw)
In-Reply-To: <20260329030943.28672-1-pengpeng@iscas.ac.cn>

On Sun, Mar 29, 2026 at 11:09:43AM +0800, Pengpeng Hou wrote:
> enclosure_link_name() prefixes the component device name with "enclosure_device:" in a fixed 64-byte stack buffer. The helper currently uses strcpy() and strcat() with no remaining-space check even though the component device name itself can approach the same length.

Please wrap your changelog lines at 72 columns.

And the buffer size is fine, no need to change that logic at all, right?

> 
> Switch the helper to bounded formatting and propagate an error when the prefixed link name does not fit.
> 
> Fixes: cb6b7f40630f ("[SCSI] ses: fix up functionality after class_device->device conversion")
> Signed-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn>
> ---
>  drivers/misc/enclosure.c | 19 ++++++++++++++-----
>  1 file changed, 14 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/misc/enclosure.c b/drivers/misc/enclosure.c
> index cf6382981777..f09707ca02e8 100644
> --- a/drivers/misc/enclosure.c
> +++ b/drivers/misc/enclosure.c
> @@ -182,17 +182,21 @@ EXPORT_SYMBOL_GPL(enclosure_unregister);
>  #define ENCLOSURE_NAME_SIZE	64
>  #define COMPONENT_NAME_SIZE	64
>  
> -static void enclosure_link_name(struct enclosure_component *cdev, char *name)
> +static int enclosure_link_name(struct enclosure_component *cdev, char *name)
>  {
> -	strcpy(name, "enclosure_device:");
> -	strcat(name, dev_name(&cdev->cdev));
> +	if (snprintf(name, ENCLOSURE_NAME_SIZE, "enclosure_device:%s",
> +		     dev_name(&cdev->cdev)) >= ENCLOSURE_NAME_SIZE)
> +		return -EINVAL;

How can this ever be triggered?

> +
> +	return 0;
>  }
>  
>  static void enclosure_remove_links(struct enclosure_component *cdev)
>  {
>  	char name[ENCLOSURE_NAME_SIZE];
>  
> -	enclosure_link_name(cdev, name);
> +	if (enclosure_link_name(cdev, name))
> +		return;
>  
>  	/*
>  	 * In odd circumstances, like multipath devices, something else may
> @@ -214,7 +218,12 @@ static int enclosure_add_links(struct enclosure_component *cdev)
>  	if (error)
>  		return error;
>  
> -	enclosure_link_name(cdev, name);
> +	error = enclosure_link_name(cdev, name);
> +	if (error) {
> +		sysfs_remove_link(&cdev->cdev.kobj, "device");

This looks like an actual real bugfix, how about just sending this
portion?

thanks,

greg k-h

  reply	other threads:[~2026-03-29  6:13 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-29  3:09 Pengpeng Hou
2026-03-29  6:13 ` Greg KH [this message]
2026-03-29  7:39 ` [PATCH v2] " Pengpeng Hou
2026-03-29  7:57   ` Greg KH
2026-03-29  8:07 ` Pengpeng Hou

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=2026032951-surely-molar-7b7a@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=James.Bottomley@hansenpartnership.com \
    --cc=arnd@arndb.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pengpeng@iscas.ac.cn \
    /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®