mirror of
https://github.com/torvalds/linux.git
synced 2026-11-07 06:17:02 +01:00
comedi: comedi_bond: Refactor strlcat() to seq_buf in do_dev_config()
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> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Link: https://patch.msgid.link/20260927060000.518354-1-nikitash.mariiaw@gmail.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
471ce96a9c
commit
6b795870cf
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user