lkml.org 
[lkml]   [2020]   [Nov]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH RFC] pwm: keembay: Fix build failure with -Os
[Cc: += linux-pwm which I forgot for the initial submission]

Hello,

On Mon, Nov 16, 2020 at 10:08:04AM +0100, Uwe Kleine-König wrote:
> The driver used this construct:
>
> #define KMB_PWM_LEADIN_MASK GENMASK(30, 0)
>
> static inline void keembay_pwm_update_bits(struct keembay_pwm *priv, u32 mask,
> u32 val, u32 offset)
> {
> u32 buff = readl(priv->base + offset);
>
> buff = u32_replace_bits(buff, val, mask);
> writel(buff, priv->base + offset);
> }
>
> ...
> keembay_pwm_update_bits(priv, KMB_PWM_LEADIN_MASK, 0,
> KMB_PWM_LEADIN_OFFSET(pwm->hwpwm));
>
> With CONFIG_CC_OPTIMIZE_FOR_SIZE the compiler (here: gcc 10.2.0) this
> triggers:
>
> In file included from /home/uwe/gsrc/linux/drivers/pwm/pwm-keembay.c:16:
> In function ‘field_multiplier’,
> inlined from ‘keembay_pwm_update_bits’ at /home/uwe/gsrc/linux/include/linux/bitfield.h:124:17:
> /home/uwe/gsrc/linux/include/linux/bitfield.h:119:3: error: call to ‘__bad_mask’ declared with attribute error: bad bitfield mask
> 119 | __bad_mask();
> | ^~~~~~~~~~~~
> In function ‘field_multiplier’,
> inlined from ‘keembay_pwm_update_bits’ at /home/uwe/gsrc/linux/include/linux/bitfield.h:154:1:
> /home/uwe/gsrc/linux/include/linux/bitfield.h:119:3: error: call to ‘__bad_mask’ declared with attribute error: bad bitfield mask
> 119 | __bad_mask();
> | ^~~~~~~~~~~~
>
> The compiler doesn't seem to be able to notice that with field being
> 0x3ffffff the expression
>
> if ((field | (field - 1)) & ((field | (field - 1)) + 1))
> __bad_mask();
>
> can be optimized away.
>
> So use __always_inline and document the problem in a comment to fix
> this.
>
> Reported-by: kernel test robot <lkp@intel.com>
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
> Hello,
>
> I'm not sure this is the right fix. Maybe the bitfield stuff can be
> changed somehow to make this problem go away, too?

Note, this patch

Fixes: cdbea243f419 ("pwm: Add PWM driver for Intel Keem Bay")

so this isn't critical for v5.10.

@thierry: If this is ok for you and Vijayakannan, you can squash this
into the original commit.

Best regards
Uwe

--
Pengutronix e.K. | Uwe Kleine-König |
Industrial Linux Solutions | https://www.pengutronix.de/ |
[unhandled content-type:application/pgp-signature]
\
 
 \ /
  Last update: 2020-11-18 11:08    [W:0.376 / U:0.016 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site