[Skiboot] [PATCH 6/7] llvm-scan-build: fix result of << is undefined

Benjamin Herrenschmidt benh at au1.ibm.com
Tue Nov 10 21:43:37 AEDT 2015


On Tue, 2015-11-10 at 18:44 +1100, Stewart Smith wrote:
> hw/fsp/fsp.c:205:13: warning: The result of the '<<' expression is
> undefined
>         return 1ul << (class - FSP_MCLASS_FIRST);
>                ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

That's not quite right...

> Signed-off-by: Stewart Smith <stewart at linux.vnet.ibm.com>
> ---
>  hw/fsp/fsp.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/fsp/fsp.c b/hw/fsp/fsp.c
> index ab625a55d16d..583476841ad1 100644
> --- a/hw/fsp/fsp.c
> +++ b/hw/fsp/fsp.c
> @@ -198,11 +198,15 @@ static struct fsp *fsp_get_active(void)
>  
>  static u64 fsp_get_class_bit(u8 class)
>  {
> +	u8 shift;
> +
>  	/* Alias classes CE and CF as the FSP has a single queue */
>  	if (class == FSP_MCLASS_IPL)
>  		class = FSP_MCLASS_SERVICE;
>  
> -	return 1ul << (class - FSP_MCLASS_FIRST);
> +	shift = class - FSP_MCLASS_FIRST;
> +	assert(shift < 64);
> +	return 1ul << shift;
>  }

And that's gross. Don't do that.

If you want to bound check class, do so with something like

assert(class >= FSP_MCLASS_FIRST && class < ...)

But that added shift variable is just hurting my eyes.

 
>  static struct fsp_cmdclass *__fsp_get_cmdclass(u8 class)



More information about the Skiboot mailing list