Re: [Nouveau] [PATCH v3 23/44] drm/nouveau/disp: add output backlight control methods

From: Timur Tabi
Date: Wed Sep 20 2023 - 15:30:39 EST


On Tue, 2023-09-19 at 17:56 -0400, Lyude Paul wrote:
> +static int
> +gt215_sor_bl_set(struct nvkm_ior *ior, int lvl)
> +{
> +       struct nvkm_device *device = ior->disp->engine.subdev.device;
> +       const u32 soff = nv50_ior_base(ior);
> +       u32 div, val;
> +
> +       div = nvkm_rd32(device, 0x61c080 + soff);
> +       val = (lvl * div) / 100;

Integer promotion rules always throw me for a loop, but since 'lvl' is a
signed integer, and div is a u32, are we sure this won't overflow? Maybe
lvl should be unsigned and val should be a u64?


> +       if (div)
> +               nvkm_wr32(device, 0x61c084 + soff, 0xc0000000 | val);

Also, maybe calculate 'val' in this if-block?