Re: [PATCH v4] Driver for ON Semi AR0521 camera sensor

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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



[Index of Archives]     [Linux Input]     [Video for Linux]     [Gstreamer Embedded]     [Mplayer Users]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux