* [PATCH] drm/nouveau: Fix memory leak in nvbios_iccsense_parse @ 2024-12-16 1:52 Zhanxin Qi 2024-12-16 9:45 ` Danilo Krummrich 0 siblings, 1 reply; 6+ messages in thread From: Zhanxin Qi @ 2024-12-16 1:52 UTC (permalink / raw) To: kherbst, lyude, dakr, airlied, simona Cc: dri-devel, nouveau, linux-kernel, Zhanxin Qi The nvbios_iccsense_parse function allocates memory for sensor data but fails to free it when the function exits, leading to a memory leak. Add proper cleanup to free the allocated memory. Signed-off-by: Zhanxin Qi <zhanxin@nfschina.com> --- drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/base.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/base.c b/drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/base.c index 8f0ccd3664eb..502608d575f7 100644 --- a/drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/base.c +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/base.c @@ -291,6 +291,9 @@ nvkm_iccsense_oneinit(struct nvkm_subdev *subdev) list_add_tail(&rail->head, &iccsense->rails); } } + + kfree(stbl.rail); + return 0; } -- 2.30.2 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] drm/nouveau: Fix memory leak in nvbios_iccsense_parse 2024-12-16 1:52 [PATCH] drm/nouveau: Fix memory leak in nvbios_iccsense_parse Zhanxin Qi @ 2024-12-16 9:45 ` Danilo Krummrich 2024-12-16 12:46 ` [PATCH v1 v1] " Zhanxin Qi 2024-12-16 13:03 ` Zhanxin Qi 0 siblings, 2 replies; 6+ messages in thread From: Danilo Krummrich @ 2024-12-16 9:45 UTC (permalink / raw) To: Zhanxin Qi Cc: kherbst, lyude, airlied, simona, dri-devel, nouveau, linux-kernel Thanks for the patch, some notes below. On Mon, Dec 16, 2024 at 09:52:46AM +0800, Zhanxin Qi wrote: > The nvbios_iccsense_parse function allocates memory for sensor data > but fails to free it when the function exits, leading to a memory > leak. Add proper cleanup to free the allocated memory. > > Signed-off-by: Zhanxin Qi <zhanxin@nfschina.com> Please also add a "Fixes:" tag and "Cc: stable@vger.kernel.org" for this. > --- > drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/base.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/base.c b/drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/base.c > index 8f0ccd3664eb..502608d575f7 100644 > --- a/drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/base.c > +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/base.c > @@ -291,6 +291,9 @@ nvkm_iccsense_oneinit(struct nvkm_subdev *subdev) > list_add_tail(&rail->head, &iccsense->rails); > } > } > + > + kfree(stbl.rail); I think it's a bit subtile why this is needed here; better add a new inline function (nvbios_iccsense_cleanup()) to include/nvkm/subdev/bios/iccsense.h that frees the memory and call this one instead. While at it, you may also want to send a separate patch, adding a brief comment to nvbios_iccsense_parse() which notes, that after a successful call to nvbios_iccsense_parse() it must be cleaned up with nvbios_iccsense_cleanup(). > + > return 0; > } > > -- > 2.30.2 > ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v1 v1] drm/nouveau: Fix memory leak in nvbios_iccsense_parse 2024-12-16 9:45 ` Danilo Krummrich @ 2024-12-16 12:46 ` Zhanxin Qi 2024-12-16 13:03 ` Zhanxin Qi 1 sibling, 0 replies; 6+ messages in thread From: Zhanxin Qi @ 2024-12-16 12:46 UTC (permalink / raw) To: kherbst, lyude, dakr, airlied, simona Cc: dri-devel, nouveau, linux-kernel, stable, Zhanxin Qi, Duanjun Li The nvbios_iccsense_parse function allocates memory for sensor data but fails to free it when the function exits, leading to a memory leak. Add proper cleanup to free the allocated memory. Fixes: 39b7e6e547ff ("drm/nouveau/nvbios/iccsense: add parsing of the SENSE table") Signed-off-by: Zhanxin Qi <zhanxin@nfschina.com> Signed-off-by: Duanjun Li <duanjun@nfschina.com> Signed-off-by: Danilo Krummrich <dakr@redhat.com> --- .../include/nvkm/subdev/bios/iccsense.h | 2 ++ .../drm/nouveau/nvkm/subdev/bios/iccsense.c | 20 +++++++++++++++++++ .../drm/nouveau/nvkm/subdev/iccsense/base.c | 3 +++ 3 files changed, 25 insertions(+) diff --git a/drivers/gpu/drm/nouveau/include/nvkm/subdev/bios/iccsense.h b/drivers/gpu/drm/nouveau/include/nvkm/subdev/bios/iccsense.h index 4c108fd2c805..8bfc28c3f7a7 100644 --- a/drivers/gpu/drm/nouveau/include/nvkm/subdev/bios/iccsense.h +++ b/drivers/gpu/drm/nouveau/include/nvkm/subdev/bios/iccsense.h @@ -20,4 +20,6 @@ struct nvbios_iccsense { }; int nvbios_iccsense_parse(struct nvkm_bios *, struct nvbios_iccsense *); + +void nvbios_iccsense_cleanup(struct nvbios_iccsense *iccsense); #endif diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/bios/iccsense.c b/drivers/gpu/drm/nouveau/nvkm/subdev/bios/iccsense.c index dea444d48f94..38fcc91ffea6 100644 --- a/drivers/gpu/drm/nouveau/nvkm/subdev/bios/iccsense.c +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/bios/iccsense.c @@ -56,6 +56,19 @@ nvbios_iccsense_table(struct nvkm_bios *bios, u8 *ver, u8 *hdr, u8 *cnt, return 0; } +/** + * nvbios_iccsense_parse - Parse ICCSENSE table from VBIOS + * @bios: VBIOS base pointer + * @iccsense: ICCSENSE table structure to fill + * + * Parses the ICCSENSE table from VBIOS and fills the provided structure. + * The caller must invoke nvbios_iccsense_cleanup() after successful parsing + * to free the allocated rail resources. + * + * Returns: + * 0 - Success + * -ENODEV - Table not found + */ int nvbios_iccsense_parse(struct nvkm_bios *bios, struct nvbios_iccsense *iccsense) { @@ -127,3 +140,10 @@ nvbios_iccsense_parse(struct nvkm_bios *bios, struct nvbios_iccsense *iccsense) return 0; } + +void +nvbios_iccsense_cleanup(struct nvbios_iccsense *iccsense) +{ + kfree(iccsense->rail); + iccsense->rail = NULL; +} diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/base.c b/drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/base.c index 8f0ccd3664eb..4c1759ecce38 100644 --- a/drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/base.c +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/base.c @@ -291,6 +291,9 @@ nvkm_iccsense_oneinit(struct nvkm_subdev *subdev) list_add_tail(&rail->head, &iccsense->rails); } } + + nvbios_iccsense_cleanup(&stbl); + return 0; } -- 2.30.2 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v1 v1] drm/nouveau: Fix memory leak in nvbios_iccsense_parse 2024-12-16 9:45 ` Danilo Krummrich 2024-12-16 12:46 ` [PATCH v1 v1] " Zhanxin Qi @ 2024-12-16 13:03 ` Zhanxin Qi 2024-12-16 14:07 ` Danilo Krummrich 1 sibling, 1 reply; 6+ messages in thread From: Zhanxin Qi @ 2024-12-16 13:03 UTC (permalink / raw) To: kherbst, lyude, dakr, airlied, simona Cc: dri-devel, nouveau, linux-kernel, stable, Zhanxin Qi, Duanjun Li The nvbios_iccsense_parse function allocates memory for sensor data but fails to free it when the function exits, leading to a memory leak. Add proper cleanup to free the allocated memory. Fixes: 39b7e6e547ff ("drm/nouveau/nvbios/iccsense: add parsing of the SENSE table") Cc: stable@vger.kernel.org Signed-off-by: Zhanxin Qi <zhanxin@nfschina.com> Signed-off-by: Duanjun Li <duanjun@nfschina.com> Signed-off-by: Danilo Krummrich <dakr@redhat.com> --- .../include/nvkm/subdev/bios/iccsense.h | 2 ++ .../drm/nouveau/nvkm/subdev/bios/iccsense.c | 20 +++++++++++++++++++ .../drm/nouveau/nvkm/subdev/iccsense/base.c | 3 +++ 3 files changed, 25 insertions(+) diff --git a/drivers/gpu/drm/nouveau/include/nvkm/subdev/bios/iccsense.h b/drivers/gpu/drm/nouveau/include/nvkm/subdev/bios/iccsense.h index 4c108fd2c805..8bfc28c3f7a7 100644 --- a/drivers/gpu/drm/nouveau/include/nvkm/subdev/bios/iccsense.h +++ b/drivers/gpu/drm/nouveau/include/nvkm/subdev/bios/iccsense.h @@ -20,4 +20,6 @@ struct nvbios_iccsense { }; int nvbios_iccsense_parse(struct nvkm_bios *, struct nvbios_iccsense *); + +void nvbios_iccsense_cleanup(struct nvbios_iccsense *iccsense); #endif diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/bios/iccsense.c b/drivers/gpu/drm/nouveau/nvkm/subdev/bios/iccsense.c index dea444d48f94..38fcc91ffea6 100644 --- a/drivers/gpu/drm/nouveau/nvkm/subdev/bios/iccsense.c +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/bios/iccsense.c @@ -56,6 +56,19 @@ nvbios_iccsense_table(struct nvkm_bios *bios, u8 *ver, u8 *hdr, u8 *cnt, return 0; } +/** + * nvbios_iccsense_parse - Parse ICCSENSE table from VBIOS + * @bios: VBIOS base pointer + * @iccsense: ICCSENSE table structure to fill + * + * Parses the ICCSENSE table from VBIOS and fills the provided structure. + * The caller must invoke nvbios_iccsense_cleanup() after successful parsing + * to free the allocated rail resources. + * + * Returns: + * 0 - Success + * -ENODEV - Table not found + */ int nvbios_iccsense_parse(struct nvkm_bios *bios, struct nvbios_iccsense *iccsense) { @@ -127,3 +140,10 @@ nvbios_iccsense_parse(struct nvkm_bios *bios, struct nvbios_iccsense *iccsense) return 0; } + +void +nvbios_iccsense_cleanup(struct nvbios_iccsense *iccsense) +{ + kfree(iccsense->rail); + iccsense->rail = NULL; +} diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/base.c b/drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/base.c index 8f0ccd3664eb..4c1759ecce38 100644 --- a/drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/base.c +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/base.c @@ -291,6 +291,9 @@ nvkm_iccsense_oneinit(struct nvkm_subdev *subdev) list_add_tail(&rail->head, &iccsense->rails); } } + + nvbios_iccsense_cleanup(&stbl); + return 0; } -- 2.30.2 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v1 v1] drm/nouveau: Fix memory leak in nvbios_iccsense_parse 2024-12-16 13:03 ` Zhanxin Qi @ 2024-12-16 14:07 ` Danilo Krummrich 2024-12-17 1:53 ` [PATCH v2] " Zhanxin Qi 0 siblings, 1 reply; 6+ messages in thread From: Danilo Krummrich @ 2024-12-16 14:07 UTC (permalink / raw) To: Zhanxin Qi Cc: kherbst, lyude, airlied, simona, dri-devel, nouveau, linux-kernel, stable, Duanjun Li The version after the inital one should be "v2". You can use git format-patch -v{VERSION_NUMBER} for this. On Mon, Dec 16, 2024 at 09:03:03PM +0800, Zhanxin Qi wrote: > The nvbios_iccsense_parse function allocates memory for sensor data > but fails to free it when the function exits, leading to a memory > leak. Add proper cleanup to free the allocated memory. > > Fixes: 39b7e6e547ff ("drm/nouveau/nvbios/iccsense: add parsing of the SENSE table") This should be Fixes: b71c0892631a ("drm/nouveau/iccsense: implement for ina209, ina219 and ina3221") instead. The function introduced by 39b7e6e547ff ("drm/nouveau/nvbios/iccsense: add parsing of the SENSE table") is correct, but the other commit did not clean up after using it. > > Cc: stable@vger.kernel.org > Signed-off-by: Zhanxin Qi <zhanxin@nfschina.com> > Signed-off-by: Duanjun Li <duanjun@nfschina.com> Why is there also Duanjun's SOB? If there is a co-author, this should be indicated with a "Co-developed-by" tag. Adding the SOB only is not sufficient, please see [1]. > Signed-off-by: Danilo Krummrich <dakr@redhat.com> Please don't add my SOB to your commits -- I'll add it when I apply the patch. Please also see [1]. [1] https://docs.kernel.org/process/submitting-patches.html#sign-your-work-the-developer-s-certificate-of-origin > --- > .../include/nvkm/subdev/bios/iccsense.h | 2 ++ > .../drm/nouveau/nvkm/subdev/bios/iccsense.c | 20 +++++++++++++++++++ > .../drm/nouveau/nvkm/subdev/iccsense/base.c | 3 +++ > 3 files changed, 25 insertions(+) > > diff --git a/drivers/gpu/drm/nouveau/include/nvkm/subdev/bios/iccsense.h b/drivers/gpu/drm/nouveau/include/nvkm/subdev/bios/iccsense.h > index 4c108fd2c805..8bfc28c3f7a7 100644 > --- a/drivers/gpu/drm/nouveau/include/nvkm/subdev/bios/iccsense.h > +++ b/drivers/gpu/drm/nouveau/include/nvkm/subdev/bios/iccsense.h > @@ -20,4 +20,6 @@ struct nvbios_iccsense { > }; > > int nvbios_iccsense_parse(struct nvkm_bios *, struct nvbios_iccsense *); > + > +void nvbios_iccsense_cleanup(struct nvbios_iccsense *iccsense); > #endif > diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/bios/iccsense.c b/drivers/gpu/drm/nouveau/nvkm/subdev/bios/iccsense.c > index dea444d48f94..38fcc91ffea6 100644 > --- a/drivers/gpu/drm/nouveau/nvkm/subdev/bios/iccsense.c > +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/bios/iccsense.c > @@ -56,6 +56,19 @@ nvbios_iccsense_table(struct nvkm_bios *bios, u8 *ver, u8 *hdr, u8 *cnt, > return 0; > } > > +/** > + * nvbios_iccsense_parse - Parse ICCSENSE table from VBIOS > + * @bios: VBIOS base pointer > + * @iccsense: ICCSENSE table structure to fill > + * > + * Parses the ICCSENSE table from VBIOS and fills the provided structure. > + * The caller must invoke nvbios_iccsense_cleanup() after successful parsing > + * to free the allocated rail resources. > + * > + * Returns: > + * 0 - Success > + * -ENODEV - Table not found > + */ Looks good, thanks for adding this! > int > nvbios_iccsense_parse(struct nvkm_bios *bios, struct nvbios_iccsense *iccsense) > { > @@ -127,3 +140,10 @@ nvbios_iccsense_parse(struct nvkm_bios *bios, struct nvbios_iccsense *iccsense) > > return 0; > } > + > +void > +nvbios_iccsense_cleanup(struct nvbios_iccsense *iccsense) > +{ > + kfree(iccsense->rail); > + iccsense->rail = NULL; > +} > diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/base.c b/drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/base.c > index 8f0ccd3664eb..4c1759ecce38 100644 > --- a/drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/base.c > +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/base.c > @@ -291,6 +291,9 @@ nvkm_iccsense_oneinit(struct nvkm_subdev *subdev) > list_add_tail(&rail->head, &iccsense->rails); > } > } > + > + nvbios_iccsense_cleanup(&stbl); > + > return 0; > } > > -- > 2.30.2 > ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2] drm/nouveau: Fix memory leak in nvbios_iccsense_parse 2024-12-16 14:07 ` Danilo Krummrich @ 2024-12-17 1:53 ` Zhanxin Qi 0 siblings, 0 replies; 6+ messages in thread From: Zhanxin Qi @ 2024-12-17 1:53 UTC (permalink / raw) To: kherbst, lyude, dakr, airlied, simona Cc: dri-devel, nouveau, linux-kernel, stable, Zhanxin Qi, Duanjun Li The nvbios_iccsense_parse function allocates memory for sensor data but fails to free it when the function exits, leading to a memory leak. Add proper cleanup to free the allocated memory. Fixes: b71c0892631a ("drm/nouveau/iccsense: implement for ina209, ina219 and ina3221") Cc: stable@vger.kernel.org Co-developed-by: Duanjun Li <duanjun@nfschina.com> Signed-off-by: Zhanxin Qi <zhanxin@nfschina.com> --- .../include/nvkm/subdev/bios/iccsense.h | 2 ++ .../drm/nouveau/nvkm/subdev/bios/iccsense.c | 20 +++++++++++++++++++ .../drm/nouveau/nvkm/subdev/iccsense/base.c | 3 +++ 3 files changed, 25 insertions(+) diff --git a/drivers/gpu/drm/nouveau/include/nvkm/subdev/bios/iccsense.h b/drivers/gpu/drm/nouveau/include/nvkm/subdev/bios/iccsense.h index 4c108fd2c805..8bfc28c3f7a7 100644 --- a/drivers/gpu/drm/nouveau/include/nvkm/subdev/bios/iccsense.h +++ b/drivers/gpu/drm/nouveau/include/nvkm/subdev/bios/iccsense.h @@ -20,4 +20,6 @@ struct nvbios_iccsense { }; int nvbios_iccsense_parse(struct nvkm_bios *, struct nvbios_iccsense *); + +void nvbios_iccsense_cleanup(struct nvbios_iccsense *iccsense); #endif diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/bios/iccsense.c b/drivers/gpu/drm/nouveau/nvkm/subdev/bios/iccsense.c index dea444d48f94..ca7c27b92f16 100644 --- a/drivers/gpu/drm/nouveau/nvkm/subdev/bios/iccsense.c +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/bios/iccsense.c @@ -56,6 +56,19 @@ nvbios_iccsense_table(struct nvkm_bios *bios, u8 *ver, u8 *hdr, u8 *cnt, return 0; } +/** + * nvbios_iccsense_parse - Parse ICCSENSE table from VBIOS + * @bios: VBIOS base pointer + * @iccsense: ICCSENSE table structure to fill + * + * Parses the ICCSENSE table from VBIOS and fills the provided structure. + * The caller must invoke nvbios_iccsense_cleanup() after successful parsing + * to free the allocated rail resources. + * + * Returns: + * 0 - Success + * -EINVAL - Table not found + */ int nvbios_iccsense_parse(struct nvkm_bios *bios, struct nvbios_iccsense *iccsense) { @@ -127,3 +140,10 @@ nvbios_iccsense_parse(struct nvkm_bios *bios, struct nvbios_iccsense *iccsense) return 0; } + +void +nvbios_iccsense_cleanup(struct nvbios_iccsense *iccsense) +{ + kfree(iccsense->rail); + iccsense->rail = NULL; +} diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/base.c b/drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/base.c index 8f0ccd3664eb..4c1759ecce38 100644 --- a/drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/base.c +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/base.c @@ -291,6 +291,9 @@ nvkm_iccsense_oneinit(struct nvkm_subdev *subdev) list_add_tail(&rail->head, &iccsense->rails); } } + + nvbios_iccsense_cleanup(&stbl); + return 0; } -- 2.30.2 ^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-12-17 10:55 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2024-12-16 1:52 [PATCH] drm/nouveau: Fix memory leak in nvbios_iccsense_parse Zhanxin Qi 2024-12-16 9:45 ` Danilo Krummrich 2024-12-16 12:46 ` [PATCH v1 v1] " Zhanxin Qi 2024-12-16 13:03 ` Zhanxin Qi 2024-12-16 14:07 ` Danilo Krummrich 2024-12-17 1:53 ` [PATCH v2] " Zhanxin Qi
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).