Re: [PATCH 1/3] s390/cpufeature: rework to allow more than only hwcap bits

From: Heiko Carstens
Date: Tue Jul 12 2022 - 15:44:20 EST


On Tue, Jul 12, 2022 at 06:46:19PM +0200, Claudio Imbrenda wrote:
> > +int cpu_have_feature(unsigned int num)
> > +{
> > + struct s390_cpu_feature *feature;
> > +
> > + feature = &s390_cpu_features[num];
>
> I would put some check to make sure you are going past the end of the
> array.
>
> Maybe something like
>
> if (num >= MAX_CPU_FEATURES) {
> WARN(1, "Invalid feature %d", num);
> return 0;

That makes sense. I would go for a simple

if (WARN_ON_ONCE(num >= MAX_CPU_FEATURES))
return 0;