[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <DU0PR04MB9417B76952E9B21E89946C09886D9@DU0PR04MB9417.eurprd04.prod.outlook.com>
Date: Thu, 4 May 2023 08:59:41 +0000
From: Peng Fan <peng.fan@....com>
To: Greg KH <gregkh@...uxfoundation.org>,
"Peng Fan (OSS)" <peng.fan@....nxp.com>
CC: "robh+dt@...nel.org" <robh+dt@...nel.org>,
"krzysztof.kozlowski+dt@...aro.org"
<krzysztof.kozlowski+dt@...aro.org>,
"rafael@...nel.org" <rafael@...nel.org>,
"andriy.shevchenko@...ux.intel.com"
<andriy.shevchenko@...ux.intel.com>,
"hdegoede@...hat.com" <hdegoede@...hat.com>,
"jgg@...pe.ca" <jgg@...pe.ca>,
"saravanak@...gle.com" <saravanak@...gle.com>,
"keescook@...omium.org" <keescook@...omium.org>,
"tglx@...utronix.de" <tglx@...utronix.de>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"abel.vesa@...aro.org" <abel.vesa@...aro.org>
Subject: RE: [PATCH] devres: provide API devm_kstrndup
Hi Greg,
> -----Original Message-----
> From: Greg KH <gregkh@...uxfoundation.org>
> Sent: 2023年5月4日 16:58
> To: Peng Fan (OSS) <peng.fan@....nxp.com>
> Cc: robh+dt@...nel.org; krzysztof.kozlowski+dt@...aro.org;
> rafael@...nel.org; andriy.shevchenko@...ux.intel.com;
> hdegoede@...hat.com; jgg@...pe.ca; saravanak@...gle.com;
> keescook@...omium.org; tglx@...utronix.de; linux-kernel@...r.kernel.org;
> abel.vesa@...aro.org; Peng Fan <peng.fan@....com>
> Subject: Re: [PATCH] devres: provide API devm_kstrndup
>
> On Thu, May 04, 2023 at 03:57:54PM +0800, Peng Fan (OSS) wrote:
> > From: Peng Fan <peng.fan@....com>
> >
> > This patch introduces devm_kstrndup API so that the device's driver
> > can allocate memory and copy string.
> >
> > Signed-off-by: Peng Fan <peng.fan@....com>
> > ---
> > drivers/base/devres.c | 28 ++++++++++++++++++++++++++++
> > include/linux/device.h | 1 +
> > 2 files changed, 29 insertions(+)
>
> We can not add apis with no users, please submit this at the same time a
> driver needs it.
>
> And what driver would need to copy a string?
https://lore.kernel.org/all/20230504085506.504474-1-peng.fan@oss.nxp.com/
Should I submit V2 with the upper patch in a patchset?
Thanks,
Peng.
>
>
> >
> > diff --git a/drivers/base/devres.c b/drivers/base/devres.c index
> > 5c998cfac335..87e2965e5bab 100644
> > --- a/drivers/base/devres.c
> > +++ b/drivers/base/devres.c
> > @@ -963,6 +963,34 @@ char *devm_kstrdup(struct device *dev, const
> char
> > *s, gfp_t gfp) } EXPORT_SYMBOL_GPL(devm_kstrdup);
> >
> > +/**
> > + * devm_kstrndup - Allocate resource managed space and
> > + * copy an existing string into that.
> > + * @dev: Device to allocate memory for
> > + * @s: the string to duplicate
> > + * @max: max length to duplicate
> > + * @gfp: the GFP mask used in the devm_kmalloc() call when allocating
> > +memory
> > + * RETURNS:
> > + * Pointer to allocated string on success, NULL on failure.
> > + */
> > +char *devm_kstrndup(struct device *dev, const char *s, size_t max,
> > +gfp_t gfp) {
> > + size_t len;
> > + char *buf;
> > +
> > + if (!s)
> > + return NULL;
> > +
> > + len = strnlen(s, max);
> > + buf = devm_kmalloc(dev, len + 1, gfp);
> > + if (buf) {
> > + memcpy(buf, s, len);
> > + buf[len] = '\0';
>
> Why not use kstrndup() instead of copying the same logic here?
>
> thanks,
>
> greg k-h
Powered by blists - more mailing lists