[Nouveau] [PATCH 1/3] drm/nouveau/i2c: fix number of aux event slots
Karol Herbst
kherbst at redhat.com
Wed Jul 19 09:00:52 UTC 2023
On Wed, Jul 19, 2023 at 6:41 AM Ben Skeggs <skeggsb at gmail.com> wrote:
>
> From: Ben Skeggs <bskeggs at redhat.com>
>
> This was completely bogus before, using maximum DCB device index rather
> than maximum AUX ID to size the buffer that stores event refcounts.
>
> *Pretty* unlikely to have been an actual problem on most configurations,
> that is, unless you've got one of the rare boards that have off-chip DP.
>
> There, it'll likely crash.
>
> Signed-off-by: Ben Skeggs <bskeggs at redhat.com>
> ---
> drivers/gpu/drm/nouveau/include/nvkm/subdev/i2c.h | 4 ++--
> drivers/gpu/drm/nouveau/nvkm/subdev/i2c/base.c | 11 +++++++++--
> 2 files changed, 11 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/nouveau/include/nvkm/subdev/i2c.h b/drivers/gpu/drm/nouveau/include/nvkm/subdev/i2c.h
> index 40a1065ae626..ef441dfdea09 100644
> --- a/drivers/gpu/drm/nouveau/include/nvkm/subdev/i2c.h
> +++ b/drivers/gpu/drm/nouveau/include/nvkm/subdev/i2c.h
> @@ -16,7 +16,7 @@ struct nvkm_i2c_bus {
> const struct nvkm_i2c_bus_func *func;
> struct nvkm_i2c_pad *pad;
> #define NVKM_I2C_BUS_CCB(n) /* 'n' is ccb index */ (n)
> -#define NVKM_I2C_BUS_EXT(n) /* 'n' is dcb external encoder type */ ((n) + 0x100)
> +#define NVKM_I2C_BUS_EXT(n) /* 'n' is dcb external encoder type */ ((n) + 0x10)
> #define NVKM_I2C_BUS_PRI /* ccb primary comm. port */ -1
> #define NVKM_I2C_BUS_SEC /* ccb secondary comm. port */ -2
> int id;
> @@ -38,7 +38,7 @@ struct nvkm_i2c_aux {
> const struct nvkm_i2c_aux_func *func;
> struct nvkm_i2c_pad *pad;
> #define NVKM_I2C_AUX_CCB(n) /* 'n' is ccb index */ (n)
> -#define NVKM_I2C_AUX_EXT(n) /* 'n' is dcb external encoder type */ ((n) + 0x100)
> +#define NVKM_I2C_AUX_EXT(n) /* 'n' is dcb external encoder type */ ((n) + 0x10)
> int id;
>
> struct mutex mutex;
> diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/i2c/base.c b/drivers/gpu/drm/nouveau/nvkm/subdev/i2c/base.c
> index 976539de4220..731b2f68d3db 100644
> --- a/drivers/gpu/drm/nouveau/nvkm/subdev/i2c/base.c
> +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/i2c/base.c
> @@ -260,10 +260,11 @@ nvkm_i2c_new_(const struct nvkm_i2c_func *func, struct nvkm_device *device,
> {
> struct nvkm_bios *bios = device->bios;
> struct nvkm_i2c *i2c;
> + struct nvkm_i2c_aux *aux;
> struct dcb_i2c_entry ccbE;
> struct dcb_output dcbE;
> u8 ver, hdr;
> - int ret, i;
> + int ret, i, ids;
>
> if (!(i2c = *pi2c = kzalloc(sizeof(*i2c), GFP_KERNEL)))
> return -ENOMEM;
> @@ -406,5 +407,11 @@ nvkm_i2c_new_(const struct nvkm_i2c_func *func, struct nvkm_device *device,
> }
> }
>
> - return nvkm_event_init(&nvkm_i2c_intr_func, &i2c->subdev, 4, i, &i2c->event);
> + ids = 0;
> + list_for_each_entry(aux, &i2c->aux, head)
> + ids = max(ids, aux->id + 1);
> + if (!ids)
> + return 0;
> +
> + return nvkm_event_init(&nvkm_i2c_intr_func, &i2c->subdev, 4, ids, &i2c->event);
> }
> --
> 2.41.0
>
Reviewed-by: Karol Herbst <kherbst at redhat.com>
More information about the Nouveau
mailing list