Re: [PATCH 02/14] drm/i915/gvt: simplify vgpu configuration management

Christoph Hellwig
2022-07-05T08:02:41Z

On Mon, Jul 04, 2022 at 11:15:36AM -0300, Jason Gunthorpe wrote:
> > + if (conf->weight < 1 || conf->weight > VGPU_MAX_WEIGHT)
> > goto out_free_types;
>
> This is now clearly impossible right? Maybe a BUILD_BUG_ON is all that
> is needed:

It is not possible right now, but an incorrect addition to the array
can easily add the condition. A BUILD_BUG_ON would be nice, but my
gcc doesn't see the expressons as const enough for that to actually work.

>
> #define VGPU_WEIGHT(vgpu_num) \
> (VGPU_MAX_WEIGHT + BUILD_BUG_ON_ZERO((vgpu_num) > VGPU_MAX_WEIGHT) / (vgpu_num))
>
> > + sprintf(gvt->types[i].name, "GVTg_V%u_%s",
> > + GRAPHICS_VER(gvt->gt->i915) == 8 ? 4 : 5, conf->name);
> > + gvt->types->conf = conf;
> > + gvt->types[i].avail_instance = min(low_avail / conf->low_mm,
> > + high_avail / conf->high_mm);
>
> snprintf and check for failure?

I'd rather just leave it as-is. intead of messing with these unrelated
bit.