2022-09-07 07:17:45

by Jianglei Nie

[permalink] [raw]
Subject: [PATCH] auxdisplay: hd44780: Fix potential memory leak in hd44780_remove()

hd44780_probe() allocates a memory chunk for hd with kzalloc() and
makes "lcd->drvdata->hd44780" point to it. When we call hd44780_remove(),
we should release all relevant memory and resource. But "lcd->drvdata
->hd44780" is not released, which will lead to a memory leak.

We should release the "lcd->drvdata->hd44780" in hd44780_remove() to fix
the memory leak bug.

Signed-off-by: Jianglei Nie <[email protected]>
---
drivers/auxdisplay/hd44780.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/auxdisplay/hd44780.c b/drivers/auxdisplay/hd44780.c
index 8b2a0eb3f32a..8940a93d2d4d 100644
--- a/drivers/auxdisplay/hd44780.c
+++ b/drivers/auxdisplay/hd44780.c
@@ -324,6 +324,7 @@ static int hd44780_remove(struct platform_device *pdev)
struct charlcd *lcd = platform_get_drvdata(pdev);

charlcd_unregister(lcd);
+ kfree(lcd->drvdata->hd44780);
kfree(lcd->drvdata);

kfree(lcd);
--
2.25.1


2022-09-07 10:00:14

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] auxdisplay: hd44780: Fix potential memory leak in hd44780_remove()

Hi Jianglei,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v6.0-rc4 next-20220906]
[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#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/Jianglei-Nie/auxdisplay-hd44780-Fix-potential-memory-leak-in-hd44780_remove/20220907-151008
base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 0066f1b0e27556381402db3ff31f85d2a2265858
config: m68k-allyesconfig (https://download.01.org/0day-ci/archive/20220907/[email protected]/config)
compiler: m68k-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/bef273823cd1f11736f4e0ce7fcf5d4ac2e1b972
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Jianglei-Nie/auxdisplay-hd44780-Fix-potential-memory-leak-in-hd44780_remove/20220907-151008
git checkout bef273823cd1f11736f4e0ce7fcf5d4ac2e1b972
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=m68k SHELL=/bin/bash drivers/

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <[email protected]>

All warnings (new ones prefixed by >>):

drivers/auxdisplay/hd44780.c: In function 'hd44780_remove':
>> drivers/auxdisplay/hd44780.c:327:27: warning: dereferencing 'void *' pointer
327 | kfree(lcd->drvdata->hd44780);
| ^~
drivers/auxdisplay/hd44780.c:327:27: error: request for member 'hd44780' in something not a structure or union


vim +327 drivers/auxdisplay/hd44780.c

321
322 static int hd44780_remove(struct platform_device *pdev)
323 {
324 struct charlcd *lcd = platform_get_drvdata(pdev);
325
326 charlcd_unregister(lcd);
> 327 kfree(lcd->drvdata->hd44780);
328 kfree(lcd->drvdata);
329
330 kfree(lcd);
331 return 0;
332 }
333

--
0-DAY CI Kernel Test Service
https://01.org/lkp

2022-09-07 10:39:34

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] auxdisplay: hd44780: Fix potential memory leak in hd44780_remove()

Hi Jianglei,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v6.0-rc4 next-20220906]
[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#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/Jianglei-Nie/auxdisplay-hd44780-Fix-potential-memory-leak-in-hd44780_remove/20220907-151008
base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 0066f1b0e27556381402db3ff31f85d2a2265858
config: microblaze-randconfig-r002-20220906
compiler: microblaze-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/bef273823cd1f11736f4e0ce7fcf5d4ac2e1b972
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Jianglei-Nie/auxdisplay-hd44780-Fix-potential-memory-leak-in-hd44780_remove/20220907-151008
git checkout bef273823cd1f11736f4e0ce7fcf5d4ac2e1b972
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=microblaze SHELL=/bin/bash drivers/auxdisplay/

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <[email protected]>

All error/warnings (new ones prefixed by >>):

drivers/auxdisplay/hd44780.c: In function 'hd44780_remove':
>> drivers/auxdisplay/hd44780.c:327:27: warning: dereferencing 'void *' pointer
327 | kfree(lcd->drvdata->hd44780);
| ^~
>> drivers/auxdisplay/hd44780.c:327:27: error: request for member 'hd44780' in something not a structure or union


vim +/hd44780 +327 drivers/auxdisplay/hd44780.c

321
322 static int hd44780_remove(struct platform_device *pdev)
323 {
324 struct charlcd *lcd = platform_get_drvdata(pdev);
325
326 charlcd_unregister(lcd);
> 327 kfree(lcd->drvdata->hd44780);
328 kfree(lcd->drvdata);
329
330 kfree(lcd);
331 return 0;
332 }
333

--
0-DAY CI Kernel Test Service
https://01.org/lkp


Attachments:
(No filename) (2.40 kB)
config (153.22 kB)
Download all attachments

2022-09-07 10:45:13

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] auxdisplay: hd44780: Fix potential memory leak in hd44780_remove()

Hi Jianglei,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v6.0-rc4 next-20220906]
[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#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/Jianglei-Nie/auxdisplay-hd44780-Fix-potential-memory-leak-in-hd44780_remove/20220907-151008
base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 0066f1b0e27556381402db3ff31f85d2a2265858
config: powerpc-randconfig-r004-20220906
compiler: clang version 16.0.0 (https://github.com/llvm/llvm-project c55b41d5199d2394dd6cdb8f52180d8b81d809d4)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install powerpc cross compiling tool for clang build
# apt-get install binutils-powerpc-linux-gnu
# https://github.com/intel-lab-lkp/linux/commit/bef273823cd1f11736f4e0ce7fcf5d4ac2e1b972
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Jianglei-Nie/auxdisplay-hd44780-Fix-potential-memory-leak-in-hd44780_remove/20220907-151008
git checkout bef273823cd1f11736f4e0ce7fcf5d4ac2e1b972
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=powerpc SHELL=/bin/bash drivers/auxdisplay/

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <[email protected]>

All errors (new ones prefixed by >>):

>> drivers/auxdisplay/hd44780.c:327:20: error: member reference base type 'void' is not a structure or union
kfree(lcd->drvdata->hd44780);
~~~~~~~~~~~~^ ~~~~~~~
1 error generated.


vim +/void +327 drivers/auxdisplay/hd44780.c

321
322 static int hd44780_remove(struct platform_device *pdev)
323 {
324 struct charlcd *lcd = platform_get_drvdata(pdev);
325
326 charlcd_unregister(lcd);
> 327 kfree(lcd->drvdata->hd44780);
328 kfree(lcd->drvdata);
329
330 kfree(lcd);
331 return 0;
332 }
333

--
0-DAY CI Kernel Test Service
https://01.org/lkp


Attachments:
(No filename) (2.43 kB)
config (150.43 kB)
Download all attachments

2022-11-24 19:29:27

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH] auxdisplay: hd44780: Fix potential memory leak in hd44780_remove()

On Wed, Sep 07, 2022 at 03:07:35PM +0800, Jianglei Nie wrote:
> hd44780_probe() allocates a memory chunk for hd with kzalloc() and
> makes "lcd->drvdata->hd44780" point to it. When we call hd44780_remove(),
> we should release all relevant memory and resource. But "lcd->drvdata
> ->hd44780" is not released, which will lead to a memory leak.
>
> We should release the "lcd->drvdata->hd44780" in hd44780_remove() to fix
> the memory leak bug.

It's pity you haven't compiled your stuff, while the analysis seems valid
to me.

What you need to do is:
1) compile on your side _before_ sending and be sure it compiles;
2) in this particular case you need an additional level of typing;
3) add Fixes tag;
4) resubmit as v2 the new version.

--
With Best Regards,
Andy Shevchenko