lkml.org 
[lkml]   [2020]   [Jun]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 2/5] mfd: lm3533-ctrlbank: Cap BRIGHTNESS_MAX to 127 since API uses u8 as carrier
On Mon, Jun 29, 2020 at 02:25:06PM +0100, Lee Jones wrote:
> On Mon, 29 Jun 2020, Johan Hovold wrote:
>
> > On Mon, Jun 29, 2020 at 01:32:12PM +0100, Lee Jones wrote:
> > > Since its conception in 2012 brightness has been artificially capped
> > > at 127 since the variable carrying the value is u8. We could go to
> > > the trouble of changing the whole API (crossing 3 different subsystems),
> > > but clearly this hasn't bothered anyone in the best part of a decade.
> > >
> > > Simply, cap BRIGHTNESS_MAX to 127 instead (for now at least).
> >
> > Hmm. This patch is clearly broken and would contrary to the claim be
> > introducing an artificial cap at half brightness. u8 can hold the max
> > brightness value 255 just fine.
>
> Yes, of course it can. Senior moment on my account.
>
> > > Fixes the following W=1 warning(s):
> > >
> > > drivers/mfd/lm3533-ctrlbank.c: In function ‘lm3533_ctrlbank_set_brightness’:
> > > drivers/mfd/lm3533-ctrlbank.c:98:10: warning: comparison is always false due to limited range of data type [-Wtype-limits]
> > > 98 | if (val > LM3533_##_NAME##_MAX) | ^
> > > drivers/mfd/lm3533-ctrlbank.c:125:1: note: in expansion of macro ‘lm3533_ctrlbank_set’
> > > 125 | lm3533_ctrlbank_set(brightness, BRIGHTNESS);
> > > | ^~~~~~~~~~~~~~~~~~~
> >
> > This warning is benign. The same macro is used to defined two function
> > where in one case the max value coincides with U8_MAX so that the sanity
> > check becomes redundant.
>
> A benign warning, as most W=1 warnings are, is still a warning.

Not every warning needs to be addressed, there's a reason some of these
are hidden behind W=1 or higher.

> So how do you propose we fix it?
>
> Is 255 a valid and used brightness level?

Yes.

> If so, how do you feel about:
>
> /* Avoid 'always false' check '(u8) > 255' */
> if (LM3533_##_NAME##_MAX != 0xff && val > LM3533_##_NAME##_MAX)
> return -EINVAL;

I'm afraid that's not sufficient to shut the compiler up.

I'll send you patch expanding these accessors instead. Having exported
functions implemented by macros is particularly nice (hard to grep for
etc). There are a couple of more sets of control-bank registers that
could potentially have shared the implementation and which motivated the
use of macros, but it does not seem very likely that we'll be adding
those anytime soon anyway.

Johan

\
 
 \ /
  Last update: 2020-06-30 10:39    [W:0.069 / U:0.820 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site