All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] comedi: comedi_bond: Refactor strlcat() to seq_buf in do_dev_config()
@ 2026-09-27  6:00 Mariia Nikitash
  2026-09-28 10:02 ` Ian Abbott
  2026-11-12 18:39 ` Kees Cook
  0 siblings, 2 replies; 5+ messages in thread
From: Mariia Nikitash @ 2026-09-27  6:00 UTC (permalink / raw)
  To: abbotti, hsweeten
  Cc: linux-kernel, linux-hardening, morbo, kees, justinstitt,
	codemender-patching+linux, Mariia Nikitash

From: Bill Wendling <morbo@google.com>

do_dev_config() builds a space-separated list of bonded devices in
devpriv->name by formatting each "minor:subdev " pair into a temporary
stack buffer with snprintf() and appending it with strlcat() in a loop.

In preparation for removing the deprecated strlcat() API[1], use struct
seq_buf and seq_buf_printf() to format each entry directly into
devpriv->name. This avoids repeated rescanning of devpriv->name and
eliminates the temporary buffer.

Link: https://github.com/KSPP/linux/issues/370 [1]
Cc: codemender-patching+linux@google.com
Assisted-by: LLM
Signed-off-by: Bill Wendling <morbo@google.com>
Signed-off-by: Mariia Nikitash <nikitash.mariiaw@gmail.com>
---
 drivers/comedi/drivers/comedi_bond.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/drivers/comedi/drivers/comedi_bond.c b/drivers/comedi/drivers/comedi_bond.c
index 8e10ecab4f0d..a10cfbd04c72 100644
--- a/drivers/comedi/drivers/comedi_bond.c
+++ b/drivers/comedi/drivers/comedi_bond.c
@@ -39,6 +39,7 @@
 
 #include <linux/module.h>
 #include <linux/string.h>
+#include <linux/seq_buf.h>
 #include <linux/slab.h>
 #include <linux/comedi.h>
 #include <linux/comedi/comedilib.h>
@@ -170,10 +171,11 @@ static int do_dev_config(struct comedi_device *dev, struct comedi_devconfig *it)
 {
 	struct comedi_bond_private *devpriv = dev->private;
 	DECLARE_BITMAP(devs_opened, COMEDI_NUM_BOARD_MINORS);
+	struct seq_buf s;
 	int i;
 
 	memset(&devs_opened, 0, sizeof(devs_opened));
-	devpriv->name[0] = 0;
+	seq_buf_init(&s, devpriv->name, sizeof(devpriv->name));
 	/*
 	 * Loop through all comedi devices specified on the command-line,
 	 * building our device list.
@@ -250,15 +252,9 @@ static int do_dev_config(struct comedi_device *dev, struct comedi_devconfig *it)
 			}
 			devpriv->devs = devs;
 			devpriv->devs[devpriv->ndevs++] = bdev;
-			{
-				/* Append dev:subdev to devpriv->name */
-				char buf[20];
-
-				snprintf(buf, sizeof(buf), "%u:%u ",
-					 bdev->minor, bdev->subdev);
-				strlcat(devpriv->name, buf,
-					sizeof(devpriv->name));
-			}
+
+			/* Append dev:subdev to devpriv->name */
+			seq_buf_printf(&s, "%u:%u ", bdev->minor, bdev->subdev);
 		}
 	}
 
@@ -267,6 +263,8 @@ static int do_dev_config(struct comedi_device *dev, struct comedi_devconfig *it)
 		return -EINVAL;
 	}
 
+	seq_buf_str(&s);
+
 	return 0;
 }
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] comedi: comedi_bond: Refactor strlcat() to seq_buf in do_dev_config()
  2026-09-27  6:00 [PATCH] comedi: comedi_bond: Refactor strlcat() to seq_buf in do_dev_config() Mariia Nikitash
@ 2026-09-28 10:02 ` Ian Abbott
  2026-11-12 18:39 ` Kees Cook
  1 sibling, 0 replies; 5+ messages in thread
From: Ian Abbott @ 2026-09-28 10:02 UTC (permalink / raw)
  To: Mariia Nikitash, hsweeten
  Cc: linux-kernel, linux-hardening, morbo, kees, justinstitt,
	codemender-patching+linux

On 27/09/2026 07:00, Mariia Nikitash wrote:
> From: Bill Wendling <morbo@google.com>
> 
> do_dev_config() builds a space-separated list of bonded devices in
> devpriv->name by formatting each "minor:subdev " pair into a temporary
> stack buffer with snprintf() and appending it with strlcat() in a loop.
> 
> In preparation for removing the deprecated strlcat() API[1], use struct
> seq_buf and seq_buf_printf() to format each entry directly into
> devpriv->name. This avoids repeated rescanning of devpriv->name and
> eliminates the temporary buffer.
> 
> Link: https://github.com/KSPP/linux/issues/370 [1]
> Cc: codemender-patching+linux@google.com
> Assisted-by: LLM
> Signed-off-by: Bill Wendling <morbo@google.com>
> Signed-off-by: Mariia Nikitash <nikitash.mariiaw@gmail.com>
> ---
>   drivers/comedi/drivers/comedi_bond.c | 18 ++++++++----------
>   1 file changed, 8 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/comedi/drivers/comedi_bond.c b/drivers/comedi/drivers/comedi_bond.c
> index 8e10ecab4f0d..a10cfbd04c72 100644
> --- a/drivers/comedi/drivers/comedi_bond.c
> +++ b/drivers/comedi/drivers/comedi_bond.c
> @@ -39,6 +39,7 @@
>   
>   #include <linux/module.h>
>   #include <linux/string.h>
> +#include <linux/seq_buf.h>
>   #include <linux/slab.h>
>   #include <linux/comedi.h>
>   #include <linux/comedi/comedilib.h>
> @@ -170,10 +171,11 @@ static int do_dev_config(struct comedi_device *dev, struct comedi_devconfig *it)
>   {
>   	struct comedi_bond_private *devpriv = dev->private;
>   	DECLARE_BITMAP(devs_opened, COMEDI_NUM_BOARD_MINORS);
> +	struct seq_buf s;
>   	int i;
>   
>   	memset(&devs_opened, 0, sizeof(devs_opened));
> -	devpriv->name[0] = 0;
> +	seq_buf_init(&s, devpriv->name, sizeof(devpriv->name));
>   	/*
>   	 * Loop through all comedi devices specified on the command-line,
>   	 * building our device list.
> @@ -250,15 +252,9 @@ static int do_dev_config(struct comedi_device *dev, struct comedi_devconfig *it)
>   			}
>   			devpriv->devs = devs;
>   			devpriv->devs[devpriv->ndevs++] = bdev;
> -			{
> -				/* Append dev:subdev to devpriv->name */
> -				char buf[20];
> -
> -				snprintf(buf, sizeof(buf), "%u:%u ",
> -					 bdev->minor, bdev->subdev);
> -				strlcat(devpriv->name, buf,
> -					sizeof(devpriv->name));
> -			}
> +
> +			/* Append dev:subdev to devpriv->name */
> +			seq_buf_printf(&s, "%u:%u ", bdev->minor, bdev->subdev);
>   		}
>   	}
>   
> @@ -267,6 +263,8 @@ static int do_dev_config(struct comedi_device *dev, struct comedi_devconfig *it)
>   		return -EINVAL;
>   	}
>   
> +	seq_buf_str(&s);
> +
>   	return 0;
>   }
>   

Looks good, thanks!

Reviewed-by: Ian Abbott <abbotti@mev.co.uk>

-- 
-=( Ian Abbott <abbotti@mev.co.uk> || MEV Ltd. is a company  )=-
-=( registered in England & Wales.  Regd. number: 02862268.  )=-
-=( Regd. addr.: S11 & 12 Building 67, Europa Business Park, )=-
-=( Bird Hall Lane, STOCKPORT, SK3 0XA, UK. || www.mev.co.uk )=-

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] comedi: comedi_bond: Refactor strlcat() to seq_buf in do_dev_config()
  2026-09-27  6:00 [PATCH] comedi: comedi_bond: Refactor strlcat() to seq_buf in do_dev_config() Mariia Nikitash
  2026-09-28 10:02 ` Ian Abbott
@ 2026-11-12 18:39 ` Kees Cook
  2026-11-12 20:16   ` Mariia Nikitash
  1 sibling, 1 reply; 5+ messages in thread
From: Kees Cook @ 2026-11-12 18:39 UTC (permalink / raw)
  To: Mariia Nikitash
  Cc: abbotti, hsweeten, linux-kernel, linux-hardening, morbo,
	justinstitt, codemender-patching+linux

On Sat, Sep 26, 2026 at 11:00:00PM -0700, Mariia Nikitash wrote:
> From: Bill Wendling <morbo@google.com>
> 
> do_dev_config() builds a space-separated list of bonded devices in
> devpriv->name by formatting each "minor:subdev " pair into a temporary
> stack buffer with snprintf() and appending it with strlcat() in a loop.
> 
> In preparation for removing the deprecated strlcat() API[1], use struct
> seq_buf and seq_buf_printf() to format each entry directly into
> devpriv->name. This avoids repeated rescanning of devpriv->name and
> eliminates the temporary buffer.
> 
> Link: https://github.com/KSPP/linux/issues/370 [1]
> Cc: codemender-patching+linux@google.com
> Assisted-by: LLM
> Signed-off-by: Bill Wendling <morbo@google.com>
> Signed-off-by: Mariia Nikitash <nikitash.mariiaw@gmail.com>
> ---
>  drivers/comedi/drivers/comedi_bond.c | 18 ++++++++----------
>  1 file changed, 8 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/comedi/drivers/comedi_bond.c b/drivers/comedi/drivers/comedi_bond.c
> index 8e10ecab4f0d..a10cfbd04c72 100644
> --- a/drivers/comedi/drivers/comedi_bond.c
> +++ b/drivers/comedi/drivers/comedi_bond.c
> @@ -39,6 +39,7 @@
>  
>  #include <linux/module.h>
>  #include <linux/string.h>
> +#include <linux/seq_buf.h>
>  #include <linux/slab.h>
>  #include <linux/comedi.h>
>  #include <linux/comedi/comedilib.h>
> @@ -170,10 +171,11 @@ static int do_dev_config(struct comedi_device *dev, struct comedi_devconfig *it)
>  {
>  	struct comedi_bond_private *devpriv = dev->private;
>  	DECLARE_BITMAP(devs_opened, COMEDI_NUM_BOARD_MINORS);
> +	struct seq_buf s;
>  	int i;
>  
>  	memset(&devs_opened, 0, sizeof(devs_opened));
> -	devpriv->name[0] = 0;
> +	seq_buf_init(&s, devpriv->name, sizeof(devpriv->name));
>  	/*
>  	 * Loop through all comedi devices specified on the command-line,
>  	 * building our device list.
> @@ -250,15 +252,9 @@ static int do_dev_config(struct comedi_device *dev, struct comedi_devconfig *it)
>  			}
>  			devpriv->devs = devs;
>  			devpriv->devs[devpriv->ndevs++] = bdev;
> -			{
> -				/* Append dev:subdev to devpriv->name */
> -				char buf[20];
> -
> -				snprintf(buf, sizeof(buf), "%u:%u ",
> -					 bdev->minor, bdev->subdev);
> -				strlcat(devpriv->name, buf,
> -					sizeof(devpriv->name));
> -			}
> +
> +			/* Append dev:subdev to devpriv->name */
> +			seq_buf_printf(&s, "%u:%u ", bdev->minor, bdev->subdev);
>  		}
>  	}
>  
> @@ -267,6 +263,8 @@ static int do_dev_config(struct comedi_device *dev, struct comedi_devconfig *it)
>  		return -EINVAL;
>  	}
>  
> +	seq_buf_str(&s);

If this hasn't been applied yet, a v2 with the above changed to the
now-available seq_buf_terminate() would be nice to have. Either way:

Reviewed-by: Kees Cook <kees@kernel.org>


> +
>  	return 0;
>  }
>  
> -- 
> 2.43.0
> 

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] comedi: comedi_bond: Refactor strlcat() to seq_buf in do_dev_config()
  2026-11-12 18:39 ` Kees Cook
@ 2026-11-12 20:16   ` Mariia Nikitash
  2026-11-12 20:32     ` Kees Cook
  0 siblings, 1 reply; 5+ messages in thread
From: Mariia Nikitash @ 2026-11-12 20:16 UTC (permalink / raw)
  To: Kees Cook
  Cc: abbotti, hsweeten, linux-kernel, linux-hardening, morbo,
	justinstitt, codemender-patching+linux

Hi!

On Thu, Nov 12, 2026 at 10:39 AM Kees Cook <kees@kernel.org> wrote:
>
> On Sat, Sep 26, 2026 at 11:00:00PM -0700, Mariia Nikitash wrote:
> > From: Bill Wendling <morbo@google.com>
> >
> > do_dev_config() builds a space-separated list of bonded devices in
> > devpriv->name by formatting each "minor:subdev " pair into a temporary
> > stack buffer with snprintf() and appending it with strlcat() in a loop.
> >
> > In preparation for removing the deprecated strlcat() API[1], use struct
> > seq_buf and seq_buf_printf() to format each entry directly into
> > devpriv->name. This avoids repeated rescanning of devpriv->name and
> > eliminates the temporary buffer.
> >
> > Link: https://github.com/KSPP/linux/issues/370 [1]
> > Cc: codemender-patching+linux@google.com
> > Assisted-by: LLM
> > Signed-off-by: Bill Wendling <morbo@google.com>
> > Signed-off-by: Mariia Nikitash <nikitash.mariiaw@gmail.com>
> > ---
> >  drivers/comedi/drivers/comedi_bond.c | 18 ++++++++----------
> >  1 file changed, 8 insertions(+), 10 deletions(-)
> >
> > diff --git a/drivers/comedi/drivers/comedi_bond.c b/drivers/comedi/drivers/comedi_bond.c
> > index 8e10ecab4f0d..a10cfbd04c72 100644
> > --- a/drivers/comedi/drivers/comedi_bond.c
> > +++ b/drivers/comedi/drivers/comedi_bond.c
> > @@ -39,6 +39,7 @@
> >
> >  #include <linux/module.h>
> >  #include <linux/string.h>
> > +#include <linux/seq_buf.h>
> >  #include <linux/slab.h>
> >  #include <linux/comedi.h>
> >  #include <linux/comedi/comedilib.h>
> > @@ -170,10 +171,11 @@ static int do_dev_config(struct comedi_device *dev, struct comedi_devconfig *it)
> >  {
> >       struct comedi_bond_private *devpriv = dev->private;
> >       DECLARE_BITMAP(devs_opened, COMEDI_NUM_BOARD_MINORS);
> > +     struct seq_buf s;
> >       int i;
> >
> >       memset(&devs_opened, 0, sizeof(devs_opened));
> > -     devpriv->name[0] = 0;
> > +     seq_buf_init(&s, devpriv->name, sizeof(devpriv->name));
> >       /*
> >        * Loop through all comedi devices specified on the command-line,
> >        * building our device list.
> > @@ -250,15 +252,9 @@ static int do_dev_config(struct comedi_device *dev, struct comedi_devconfig *it)
> >                       }
> >                       devpriv->devs = devs;
> >                       devpriv->devs[devpriv->ndevs++] = bdev;
> > -                     {
> > -                             /* Append dev:subdev to devpriv->name */
> > -                             char buf[20];
> > -
> > -                             snprintf(buf, sizeof(buf), "%u:%u ",
> > -                                      bdev->minor, bdev->subdev);
> > -                             strlcat(devpriv->name, buf,
> > -                                     sizeof(devpriv->name));
> > -                     }
> > +
> > +                     /* Append dev:subdev to devpriv->name */
> > +                     seq_buf_printf(&s, "%u:%u ", bdev->minor, bdev->subdev);
> >               }
> >       }
> >
> > @@ -267,6 +263,8 @@ static int do_dev_config(struct comedi_device *dev, struct comedi_devconfig *it)
> >               return -EINVAL;
> >       }
> >
> > +     seq_buf_str(&s);
>
> If this hasn't been applied yet, a v2 with the above changed to the
> now-available seq_buf_terminate() would be nice to have. Either way:
>
> Reviewed-by: Kees Cook <kees@kernel.org>


Thanks for the review! This patch has already been merged, but I'd be
happy to send a follow up patch with seq_buf_terminate() if you'd
like.

>
>
> > +
> >       return 0;
> >  }
> >
> > --
> > 2.43.0
> >
>
> --
> Kees Cook

Best,
Mariia

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] comedi: comedi_bond: Refactor strlcat() to seq_buf in do_dev_config()
  2026-11-12 20:16   ` Mariia Nikitash
@ 2026-11-12 20:32     ` Kees Cook
  0 siblings, 0 replies; 5+ messages in thread
From: Kees Cook @ 2026-11-12 20:32 UTC (permalink / raw)
  To: Mariia Nikitash
  Cc: abbotti, hsweeten, linux-kernel, linux-hardening, morbo,
	justinstitt, codemender-patching+linux

On Thu, Nov 12, 2026 at 12:16:11PM -0800, Mariia Nikitash wrote:
> Thanks for the review! This patch has already been merged, but I'd be
> happy to send a follow up patch with seq_buf_terminate() if you'd
> like.

Nah, it's fine. :) I don't see value in the churn since the binary
output will be identical.

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-12 20:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-27  6:00 [PATCH] comedi: comedi_bond: Refactor strlcat() to seq_buf in do_dev_config() Mariia Nikitash
2026-09-28 10:02 ` Ian Abbott
2026-11-12 18:39 ` Kees Cook
2026-11-12 20:16   ` Mariia Nikitash
2026-11-12 20:32     ` Kees Cook

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.