public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: "Peng Fan (OSS)" <peng.fan@oss.nxp.com>
Cc: gregkh@linuxfoundation.org, robh+dt@kernel.org,
	krzysztof.kozlowski+dt@linaro.org, rafael@kernel.org,
	hdegoede@redhat.com, jgg@ziepe.ca, saravanak@google.com,
	keescook@chromium.org, tglx@linutronix.de,
	linux-kernel@vger.kernel.org, abel.vesa@linaro.org,
	Peng Fan <peng.fan@nxp.com>
Subject: Re: [PATCH] devres: provide API devm_kstrndup
Date: Thu, 4 May 2023 17:38:27 +0300	[thread overview]
Message-ID: <ZFPDYwa8ko6ZUEEL@smile.fi.intel.com> (raw)
In-Reply-To: <20230504075754.372780-1-peng.fan@oss.nxp.com>

On Thu, May 04, 2023 at 03:57:54PM +0800, Peng Fan (OSS) wrote:
> From: Peng Fan <peng.fan@nxp.com>
> 
> This patch introduces devm_kstrndup API so that the
> device's driver can allocate memory and copy string.

...

> +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);

besides this to be open coded devm_kmemdup()

> +		buf[len] = '\0';
> +	}
> +	return buf;
> +}

you can always use devm_add_action_or_reset() for a single user before
we introduce a new wide API.

-- 
With Best Regards,
Andy Shevchenko



      parent reply	other threads:[~2023-05-04 14:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-04  7:57 [PATCH] devres: provide API devm_kstrndup Peng Fan (OSS)
2023-05-04  8:58 ` Greg KH
2023-05-04  8:59   ` Peng Fan
2023-05-04  9:08     ` Greg KH
2023-05-04 14:38 ` Andy Shevchenko [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=ZFPDYwa8ko6ZUEEL@smile.fi.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=abel.vesa@linaro.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=hdegoede@redhat.com \
    --cc=jgg@ziepe.ca \
    --cc=keescook@chromium.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peng.fan@nxp.com \
    --cc=peng.fan@oss.nxp.com \
    --cc=rafael@kernel.org \
    --cc=robh+dt@kernel.org \
    --cc=saravanak@google.com \
    --cc=tglx@linutronix.de \
    /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