* [PATCH] drivers/md: fix potential memleak
@ 2021-11-15 3:18 Bernard Zhao
2021-11-17 7:06 ` Song Liu
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Bernard Zhao @ 2021-11-15 3:18 UTC (permalink / raw)
To: Song Liu, linux-raid, linux-kernel; +Cc: Bernard Zhao
In function get_bitmap_from_slot, when md_bitmap_create failed,
md_bitmap_destroy must be called to do clean up.
Signed-off-by: Bernard Zhao <bernard@vivo.com>
---
drivers/md/md-bitmap.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
index bfd6026d7809..a227bd0b9301 100644
--- a/drivers/md/md-bitmap.c
+++ b/drivers/md/md-bitmap.c
@@ -1961,6 +1961,7 @@ struct bitmap *get_bitmap_from_slot(struct mddev *mddev, int slot)
bitmap = md_bitmap_create(mddev, slot);
if (IS_ERR(bitmap)) {
rv = PTR_ERR(bitmap);
+ md_bitmap_destroy(mddev)
return ERR_PTR(rv);
}
--
2.33.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] drivers/md: fix potential memleak
2021-11-15 3:18 [PATCH] drivers/md: fix potential memleak Bernard Zhao
@ 2021-11-17 7:06 ` Song Liu
[not found] ` <AE6ABwAlE-AV3TdOtnvxCKoI.9.1637132794891.Hmail.bernard@vivo.com.@PENBUGhzdVc2dWk9d0JyVG9Za3FFT3BMeUxZaGpITW95MG1MMFVNY1hucTBPYktMTGhvQUBtYWlsLmdtYWlsLmNvbT4=>
2021-11-17 16:44 ` kernel test robot
2 siblings, 0 replies; 5+ messages in thread
From: Song Liu @ 2021-11-17 7:06 UTC (permalink / raw)
To: bernard; +Cc: linux-raid, open list
On Sun, Nov 14, 2021 at 7:18 PM Bernard Zhao <bernard@vivo.com> wrote:
>
> In function get_bitmap_from_slot, when md_bitmap_create failed,
> md_bitmap_destroy must be called to do clean up.
Could you please explain which variable(s) need clean up?
Thanks,
Song
>
> Signed-off-by: Bernard Zhao <bernard@vivo.com>
> ---
> drivers/md/md-bitmap.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
> index bfd6026d7809..a227bd0b9301 100644
> --- a/drivers/md/md-bitmap.c
> +++ b/drivers/md/md-bitmap.c
> @@ -1961,6 +1961,7 @@ struct bitmap *get_bitmap_from_slot(struct mddev *mddev, int slot)
> bitmap = md_bitmap_create(mddev, slot);
> if (IS_ERR(bitmap)) {
> rv = PTR_ERR(bitmap);
> + md_bitmap_destroy(mddev)
> return ERR_PTR(rv);
> }
>
> --
> 2.33.1
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* 答复: [PATCH] drivers/md: fix potential memleak
[not found] ` <AE6ABwAlE-AV3TdOtnvxCKoI.9.1637132794891.Hmail.bernard@vivo.com.@PENBUGhzdVc2dWk9d0JyVG9Za3FFT3BMeUxZaGpITW95MG1MMFVNY1hucTBPYktMTGhvQUBtYWlsLmdtYWlsLmNvbT4=>
@ 2021-11-17 7:57 ` 赵军奎
2021-11-20 7:23 ` Song Liu
0 siblings, 1 reply; 5+ messages in thread
From: 赵军奎 @ 2021-11-17 7:57 UTC (permalink / raw)
To: Song Liu; +Cc: linux-raid, open list
-----邮件原件-----
发件人: bernard@vivo.com <bernard@vivo.com> 代表 Song Liu
发送时间: 2021年11月17日 15:06
收件人: 赵军奎 <bernard@vivo.com>
抄送: linux-raid <linux-raid@vger.kernel.org>; open list <linux-kernel@vger.kernel.org>
主题: Re: [PATCH] drivers/md: fix potential memleak
On Sun, Nov 14, 2021 at 7:18 PM Bernard Zhao <bernard@vivo.com> wrote:
>
> In function get_bitmap_from_slot, when md_bitmap_create failed,
> md_bitmap_destroy must be called to do clean up.
>Could you please explain which variable(s) need clean up?
Hi Song:
The follow is the function md_bitmap_create`s annotation :
/*
* initialize the bitmap structure
* if this returns an error, bitmap_destroy must be called to do clean up
* once mddev->bitmap is set
*/
struct bitmap *md_bitmap_create(struct mddev *mddev, int slot)
It is mentioned that bitmap_destroy needs to be called to do clean up.
Other functions which called md_bitmap_create in the same file also called md_bitmap_create to clean up(in the error branch), but this one didn`t.
I am not sure if there is some gap?
Thanks!
BR//Bernard
>Thanks,
>Song
>
> Signed-off-by: Bernard Zhao <bernard@vivo.com>
> ---
> drivers/md/md-bitmap.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c index
> bfd6026d7809..a227bd0b9301 100644
> --- a/drivers/md/md-bitmap.c
> +++ b/drivers/md/md-bitmap.c
> @@ -1961,6 +1961,7 @@ struct bitmap *get_bitmap_from_slot(struct mddev *mddev, int slot)
> bitmap = md_bitmap_create(mddev, slot);
> if (IS_ERR(bitmap)) {
> rv = PTR_ERR(bitmap);
> + md_bitmap_destroy(mddev)
> return ERR_PTR(rv);
> }
>
> --
> 2.33.1
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] drivers/md: fix potential memleak
2021-11-15 3:18 [PATCH] drivers/md: fix potential memleak Bernard Zhao
2021-11-17 7:06 ` Song Liu
[not found] ` <AE6ABwAlE-AV3TdOtnvxCKoI.9.1637132794891.Hmail.bernard@vivo.com.@PENBUGhzdVc2dWk9d0JyVG9Za3FFT3BMeUxZaGpITW95MG1MMFVNY1hucTBPYktMTGhvQUBtYWlsLmdtYWlsLmNvbT4=>
@ 2021-11-17 16:44 ` kernel test robot
2 siblings, 0 replies; 5+ messages in thread
From: kernel test robot @ 2021-11-17 16:44 UTC (permalink / raw)
To: Bernard Zhao, Song Liu, linux-raid, linux-kernel; +Cc: kbuild-all, Bernard Zhao
[-- Attachment #1: Type: text/plain, Size: 2435 bytes --]
Hi Bernard,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on song-md/md-next]
[also build test ERROR on v5.16-rc1 next-20211117]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Bernard-Zhao/drivers-md-fix-potential-memleak/20211115-112133
base: git://git.kernel.org/pub/scm/linux/kernel/git/song/md.git md-next
config: x86_64-rhel-8.3-func (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce (this is a W=1 build):
# https://github.com/0day-ci/linux/commit/0d67c5d17f8404c6975f34e0c0edccdaa9ab913d
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Bernard-Zhao/drivers-md-fix-potential-memleak/20211115-112133
git checkout 0d67c5d17f8404c6975f34e0c0edccdaa9ab913d
# save the attached .config to linux build tree
mkdir build_dir
make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash drivers/iommu/ drivers/md/ drivers/misc/sgi-gru/ fs/
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
All errors (new ones prefixed by >>):
drivers/md/md-bitmap.c: In function 'get_bitmap_from_slot':
>> drivers/md/md-bitmap.c:1964:27: error: expected ';' before 'return'
1964 | md_bitmap_destroy(mddev)
| ^
| ;
1965 | return ERR_PTR(rv);
| ~~~~~~
vim +1964 drivers/md/md-bitmap.c
1954
1955 /* caller need to free returned bitmap with md_bitmap_free() */
1956 struct bitmap *get_bitmap_from_slot(struct mddev *mddev, int slot)
1957 {
1958 int rv = 0;
1959 struct bitmap *bitmap;
1960
1961 bitmap = md_bitmap_create(mddev, slot);
1962 if (IS_ERR(bitmap)) {
1963 rv = PTR_ERR(bitmap);
> 1964 md_bitmap_destroy(mddev)
1965 return ERR_PTR(rv);
1966 }
1967
1968 rv = md_bitmap_init_from_disk(bitmap, 0);
1969 if (rv) {
1970 md_bitmap_free(bitmap);
1971 return ERR_PTR(rv);
1972 }
1973
1974 return bitmap;
1975 }
1976 EXPORT_SYMBOL(get_bitmap_from_slot);
1977
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 41482 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] drivers/md: fix potential memleak
2021-11-17 7:57 ` 答复: " 赵军奎
@ 2021-11-20 7:23 ` Song Liu
0 siblings, 0 replies; 5+ messages in thread
From: Song Liu @ 2021-11-20 7:23 UTC (permalink / raw)
To: 赵军奎; +Cc: linux-raid, open list
On Tue, Nov 16, 2021 at 9:57 PM 赵军奎 <bernard@vivo.com> wrote:
>
>
>
> -----邮件原件-----
> 发件人: bernard@vivo.com <bernard@vivo.com> 代表 Song Liu
> 发送时间: 2021年11月17日 15:06
> 收件人: 赵军奎 <bernard@vivo.com>
> 抄送: linux-raid <linux-raid@vger.kernel.org>; open list <linux-kernel@vger.kernel.org>
> 主题: Re: [PATCH] drivers/md: fix potential memleak
>
> On Sun, Nov 14, 2021 at 7:18 PM Bernard Zhao <bernard@vivo.com> wrote:
> >
> > In function get_bitmap_from_slot, when md_bitmap_create failed,
> > md_bitmap_destroy must be called to do clean up.
>
> >Could you please explain which variable(s) need clean up?
>
> Hi Song:
> The follow is the function md_bitmap_create`s annotation :
> /*
> * initialize the bitmap structure
> * if this returns an error, bitmap_destroy must be called to do clean up
> * once mddev->bitmap is set
> */
> struct bitmap *md_bitmap_create(struct mddev *mddev, int slot)
>
> It is mentioned that bitmap_destroy needs to be called to do clean up.
> Other functions which called md_bitmap_create in the same file also called md_bitmap_create to clean up(in the error branch), but this one didn`t.
> I am not sure if there is some gap?
I don't think we need to call md_bitmap_destroy in some of these cases.
Please read the code carefully can decide where these are needed based
on the logic of the code.
Thanks,
Song
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-11-20 7:24 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-15 3:18 [PATCH] drivers/md: fix potential memleak Bernard Zhao
2021-11-17 7:06 ` Song Liu
[not found] ` <AE6ABwAlE-AV3TdOtnvxCKoI.9.1637132794891.Hmail.bernard@vivo.com.@PENBUGhzdVc2dWk9d0JyVG9Za3FFT3BMeUxZaGpITW95MG1MMFVNY1hucTBPYktMTGhvQUBtYWlsLmdtYWlsLmNvbT4=>
2021-11-17 7:57 ` 答复: " 赵军奎
2021-11-20 7:23 ` Song Liu
2021-11-17 16:44 ` kernel test robot
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).