Keita Suzuki
2020-Oct-14 07:54 UTC
[Nouveau] [PATCH RFC] drm/nouveau: fix memory leak in nvkm_iccsense_oneinit
struct pw_rail_t is allocated as an array in function nvios_iccsense_parse, and stored to a struct member of local variable. However, the array is not freed when the local variable becomes invalid, and the reference is not passed on, leading to a memory leak. Fix this by freeing struct pw_rail_t when exiting nvkm_iccsense_oneinit. Signed-off-by: Keita Suzuki <keitasuzuki.park at sslab.ics.keio.ac.jp> --- drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/base.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/base.c b/drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/base.c index fecfa6afcf54..8ba8d8e3f52a 100644 --- a/drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/base.c +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/base.c @@ -280,8 +280,10 @@ nvkm_iccsense_oneinit(struct nvkm_subdev *subdev) } rail = kmalloc(sizeof(*rail), GFP_KERNEL); - if (!rail) + if (!rail) { + kfree(stbl.rail); return -ENOMEM; + } rail->read = read; rail->sensor = sensor; @@ -291,6 +293,7 @@ nvkm_iccsense_oneinit(struct nvkm_subdev *subdev) list_add_tail(&rail->head, &iccsense->rails); } } + kfree(stbl.rail); return 0; } -- 2.17.1
Karol Herbst
2020-Oct-15 16:32 UTC
[Nouveau] [PATCH RFC] drm/nouveau: fix memory leak in nvkm_iccsense_oneinit
Ben, I think this is like the 5th patch tackling this issue, I think we should merge one of those. On Thu, Oct 15, 2020 at 6:23 AM Keita Suzuki <keitasuzuki.park at sslab.ics.keio.ac.jp> wrote:> > struct pw_rail_t is allocated as an array in function nvios_iccsense_parse, > and stored to a struct member of local variable. However, the array is not > freed when the local variable becomes invalid, and the reference is not > passed on, leading to a memory leak. > > Fix this by freeing struct pw_rail_t when exiting nvkm_iccsense_oneinit. > > Signed-off-by: Keita Suzuki <keitasuzuki.park at sslab.ics.keio.ac.jp> > --- > drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/base.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/base.c b/drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/base.c > index fecfa6afcf54..8ba8d8e3f52a 100644 > --- a/drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/base.c > +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/base.c > @@ -280,8 +280,10 @@ nvkm_iccsense_oneinit(struct nvkm_subdev *subdev) > } > > rail = kmalloc(sizeof(*rail), GFP_KERNEL); > - if (!rail) > + if (!rail) { > + kfree(stbl.rail); > return -ENOMEM; > + } > > rail->read = read; > rail->sensor = sensor; > @@ -291,6 +293,7 @@ nvkm_iccsense_oneinit(struct nvkm_subdev *subdev) > list_add_tail(&rail->head, &iccsense->rails); > } > } > + kfree(stbl.rail); > return 0; > } > > -- > 2.17.1 > > _______________________________________________ > Nouveau mailing list > Nouveau at lists.freedesktop.org > https://lists.freedesktop.org/mailman/listinfo/nouveau >
Karol Herbst
2020-Oct-15 17:03 UTC
[Nouveau] [PATCH RFC] drm/nouveau: fix memory leak in nvkm_iccsense_oneinit
On Thu, Oct 15, 2020 at 6:32 PM Karol Herbst <kherbst at redhat.com> wrote:> > Ben, I think this is like the 5th patch tackling this issue, I think > we should merge one of those. >maybe I just confused that with reports, but it seems to turn up quite a bit and maybe I should have pushed more of it as well... Anyway, the patch itself looks good. Reviewed-by: Karol Herbst <kherbst at redhat.com>> On Thu, Oct 15, 2020 at 6:23 AM Keita Suzuki > <keitasuzuki.park at sslab.ics.keio.ac.jp> wrote: > > > > struct pw_rail_t is allocated as an array in function nvios_iccsense_parse, > > and stored to a struct member of local variable. However, the array is not > > freed when the local variable becomes invalid, and the reference is not > > passed on, leading to a memory leak. > > > > Fix this by freeing struct pw_rail_t when exiting nvkm_iccsense_oneinit. > > > > Signed-off-by: Keita Suzuki <keitasuzuki.park at sslab.ics.keio.ac.jp> > > --- > > drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/base.c | 5 ++++- > > 1 file changed, 4 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/base.c b/drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/base.c > > index fecfa6afcf54..8ba8d8e3f52a 100644 > > --- a/drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/base.c > > +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/base.c > > @@ -280,8 +280,10 @@ nvkm_iccsense_oneinit(struct nvkm_subdev *subdev) > > } > > > > rail = kmalloc(sizeof(*rail), GFP_KERNEL); > > - if (!rail) > > + if (!rail) { > > + kfree(stbl.rail); > > return -ENOMEM; > > + } > > > > rail->read = read; > > rail->sensor = sensor; > > @@ -291,6 +293,7 @@ nvkm_iccsense_oneinit(struct nvkm_subdev *subdev) > > list_add_tail(&rail->head, &iccsense->rails); > > } > > } > > + kfree(stbl.rail); > > return 0; > > } > > > > -- > > 2.17.1 > > > > _______________________________________________ > > Nouveau mailing list > > Nouveau at lists.freedesktop.org > > https://lists.freedesktop.org/mailman/listinfo/nouveau > >
Seemingly Similar Threads
- [PATCH RFC] drm/nouveau: fix memory leak in nvkm_iccsense_oneinit
- [PATCH 0/4] Configure Power Sensors
- [PATCH v2 0/4] Configure Power Sensors
- [PATCH v4 0/3] Expose power budget cap via hwmon
- [PATCH] drm/nouveau/iccsense: fix memory leak on default sensor->type case