linux/drivers/video/backlight
Jesper Juhl 0b75f2dfa2 backlight: Fix cr_bllcd allocations and error paths
After fixing the too small memory allocation in cr_backlight_probe()
from drivers/video/backlight/cr_bllcd.c
(commit e3bbb3f053) I noticed that the
Coverity checker also thought there were a few memory leaks in there.
I took a closer look and confirmed that there were indeed several
leaks.

At the start of the function we allocate storage for a
'struct cr_panel' and store the pointer in a variable named 'crp'.

Then we call pci_get_device() and pci_read_config_byte() and if
either of them fail we return without freeing the memory allocated
for the 'struct cr_panel'. These two leaks are easy to fix since we
don't even use 'crp' for anything up to this point, so I simply
moved the allocation further down in the function so it only happens
just before we actually need it.

A bit further down we call backlight_device_register() and store the
result in 'crp->cr_backlight_device'. In case of error we return
'crp->cr_backlight_device' from the function, thus leaking 'crp'
itself. The same thing happens with the call to lcd_device_register().
To fix these two leaks I declare two new pointers to hold the return
values, so that in case of error we can return the pointer (as before)
but without leaking 'crp'.

This version of the patch also adds missing
backlight_device_unregister() / lcd_device_unregister() / pci_dev_put()
calls to error paths.
  Thanks to Richard Purdie <rpurdie@rpsys.net> for noticing.

Signed-off-by: Jesper Juhl <jesper.juhl@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Richard Purdie <rpurdie@rpsys.net>
2007-10-11 22:24:12 +01:00
..
backlight.c backlight/leds: Make two structs static 2007-10-11 22:24:12 +01:00
corgi_bl.c backlight: simplify corgi_bl locking 2007-02-20 09:26:54 +00:00
cr_bllcd.c backlight: Fix cr_bllcd allocations and error paths 2007-10-11 22:24:12 +01:00
hp680_bl.c backlight: Separate backlight properties from backlight ops pointers 2007-02-20 09:26:53 +00:00
Kconfig backlight: Fix order of Kconfig entries 2007-07-16 01:16:36 +01:00
lcd.c backlight/leds: Make two structs static 2007-10-11 22:24:12 +01:00
locomolcd.c [ARM] 4250/1: Fix locomo backlight conversion error/compile failure 2007-03-08 13:34:01 +00:00
Makefile vmlfb: framebuffer driver for Intel Vermilion Range 2007-05-08 11:15:32 -07:00
progear_bl.c [PATCH] misc NULL noise 2007-03-14 15:27:49 -07:00