Re: linux-next: dock_link_device is oopsy

From: Hillf Danton
Date: Sat Feb 18 2012 - 08:37:20 EST


On Sat, Feb 18, 2012 at 9:26 PM, Holger Macht <holger@xxxxxxxx> wrote:
> On Sa 18. Feb - 21:05:18, Hillf Danton wrote:
>> On Sat, Feb 18, 2012 at 7:14 PM, Holger Macht <holger@xxxxxxxx> wrote:
>> > So how about that?
>> >
>> > acpi: Bail out when linking devices and there are no dock stations
>> >
>> > If dock_station_count is zero, we allocate zero memory and don't check
>> > this at future references. So bail out if there are actually no dock
>> > stations.
>> >
>> > Signed-off-by: Holger Macht <holger@xxxxxxxx>
>> > ---
>> > Âdrivers/acpi/dock.c | Â 19 ++++++++++++++-----
>> > Â1 files changed, 14 insertions(+), 5 deletions(-)
>> >
>> > diff --git a/drivers/acpi/dock.c b/drivers/acpi/dock.c
>> > index b5e4142..0b3072c 100644
>> > --- a/drivers/acpi/dock.c
>> > +++ b/drivers/acpi/dock.c
>> > @@ -281,11 +281,15 @@ EXPORT_SYMBOL_GPL(is_dock_device);
>> > Â*/
>> > Âstruct device **dock_link_device(acpi_handle handle)
>> > Â{
>> > - Â Â Â struct device *dev = acpi_get_physical_device(handle);
>> > + Â Â Â struct device *dev;
>> > Â Â Â Âstruct dock_station *dock_station;
>> > Â Â Â Âint ret, dock = 0;
>> > Â Â Â Âstruct device **devices;
>> >
>> > + Â Â Â if (!dock_station_count)
>> > + Â Â Â Â Â Â Â return NULL;
>> > +
>> > + Â Â Â dev = acpi_get_physical_device(handle);
>> > Â Â Â Âdevices = kmalloc(dock_station_count * sizeof(struct device *),
>> > Â Â Â Â Â Â Â Â Â Â Â Â ÂGFP_KERNEL);
>> >
>> > @@ -320,12 +324,17 @@ EXPORT_SYMBOL_GPL(dock_link_device);
>> > Â*/
>> > Âstruct device **dock_unlink_device(acpi_handle handle)
>> > Â{
>> > - Â Â Â struct device *dev = acpi_get_physical_device(handle);
>> > + Â Â Â struct device *dev;
>> > Â Â Â Âstruct dock_station *dock_station;
>> > Â Â Â Âint dock = 0;
>> > - Â Â Â struct device **devices =
>> > - Â Â Â Â Â Â Â kmalloc(dock_station_count * sizeof(struct device *),
>> > - Â Â Â Â Â Â Â Â Â Â Â GFP_KERNEL);
>> > + Â Â Â struct device **devices;
>> > +
>> > + Â Â Â if (!dock_station_count)
>> > + Â Â Â Â Â Â Â return NULL;
>> > +
>> > + Â Â Â dev = acpi_get_physical_device(handle);
>> > + Â Â Â devices = kmalloc(dock_station_count * sizeof(struct device *),
>> > + Â Â Â Â Â Â Â Â Â Â Â Â GFP_KERNEL);
>> >
>>
>> If bail out in this way, another patch looks needed to fix up
>> mem leakage :-(
>
> Sorry if I'm a little slow...but where is the leakage? The function
> doesn't allocate anything before bailing out in the dock_station_count
> check. And the rerun value should be freed by the caller. Please point
> me in the right direction.
>

Hi ÂHolger

Lets check the following snippet from what you posted,

> @@ -320,12 +324,17 @@ EXPORT_SYMBOL_GPL(dock_link_device);
> Â*/
> Âstruct device **dock_unlink_device(acpi_handle handle)
> Â{
> - Â Â Â struct device *dev = acpi_get_physical_device(handle);
> + Â Â Â struct device *dev;
> Â Â Â Âstruct dock_station *dock_station;
> Â Â Â Âint dock = 0;
> - Â Â Â struct device **devices =
> - Â Â Â Â Â Â Â kmalloc(dock_station_count * sizeof(struct device *),
> - Â Â Â Â Â Â Â Â Â Â Â GFP_KERNEL);
> + Â Â Â struct device **devices;
> +
> + Â Â Â if (!dock_station_count)
> + Â Â Â Â Â Â Â return NULL;
> +
> + Â Â Â dev = acpi_get_physical_device(handle);
> + Â Â Â devices = kmalloc(dock_station_count * sizeof(struct device *),
> + Â Â Â Â Â Â Â Â Â Â Â Â GFP_KERNEL);
>
> Â Â Â Âif (!dev)
> Â Â Â Â Â Â Â Âreturn NULL; <=== here return without freeing the newly
allocated devices after checking
dock_station_count is not zero
> --
> 1.7.7
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/