LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Sakari Ailus <sakari.ailus@iki.fi>
To: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: "Krzysztof Hałasa" <khalasa@piap.pl>,
	"Mauro Carvalho Chehab" <mchehab@kernel.org>,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4] Driver for ON Semi AR0521 camera sensor
Date: Wed, 18 Aug 2021 23:15:46 +0300	[thread overview]
Message-ID: <YR1qckqUpUwnm3IT@valkosipuli.retiisi.eu> (raw)
In-Reply-To: <YR053s0EoYrz/RcP@pendragon.ideasonboard.com>

On Wed, Aug 18, 2021 at 07:48:30PM +0300, Laurent Pinchart wrote:
> > > +static const char *mhz(u32 value)
> > > +{
> > > +	static char buff[32];
> > > +
> > > +	if (value % 1000)
> > > +		sprintf(buff, "%u.%06u", value / (1000 * 1000), value % (1000 * 1000));
> > > +	else if (value % (1000 * 1000))
> > > +		sprintf(buff, "%u.%03u", value / (1000 * 1000), (value / 1000) % 1000);
> > > +	else
> > > +		sprintf(buff, "%u", value / (1000 * 1000));
> > > +	return buff;
> > 
> > Sorry, you can't do that. buff is allocated in the stack and the memory is
> > no longer available once the function returns.
> 
> It's a static char array, so it won't be allocated on the stack, but
> it's still bad practice as it's not thread-safe. Given that it's used in

Ah, yeah. I missed the static there.

> two debugging messages only, I'd hardcode the %u.06%u format in the
> callers.

Or just plain number in Hz. Both are fine though.

-- 
Sakari Ailus

  reply	other threads:[~2021-08-18 20:15 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-30  7:41 Krzysztof Hałasa
2021-08-18 16:29 ` Sakari Ailus
2021-08-18 16:48   ` Laurent Pinchart
2021-08-18 20:15     ` Sakari Ailus [this message]
2021-08-30  7:22   ` Krzysztof Hałasa

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=YR1qckqUpUwnm3IT@valkosipuli.retiisi.eu \
    --to=sakari.ailus@iki.fi \
    --cc=khalasa@piap.pl \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --subject='Re: [PATCH v4] Driver for ON Semi AR0521 camera sensor' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).