Skip to content

Commit

Permalink
platform/x86/dell/dell-rbtn: Fix resources leaking on error path
Browse files Browse the repository at this point in the history
[ Upstream commit 966cca7 ]

Currently rbtn_add() in case of failure is leaking resources. Fix this
by adding a proper rollback. Move devm_kzalloc() before rbtn_acquire(),
so it doesn't require rollback in case of failure. While at it, remove
unnecessary assignment of NULL to device->driver_data and unnecessary
whitespace, plus add a break for the default case in a switch.

Suggested-by: Ilpo Järvinen <[email protected]>
Suggested-by: Pali Rohár <[email protected]>
Fixes: 817a5cd ("dell-rbtn: Dell Airplane Mode Switch driver")
Signed-off-by: Michal Wilczynski <[email protected]>
Reviewed-by: Andy Shevchenko <[email protected]>
Acked-by: Rafael J. Wysocki <[email protected]>
Reviewed-by: Pali Rohár <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Reviewed-by: Hans de Goede <[email protected]>
Signed-off-by: Hans de Goede <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
  • Loading branch information
mwilczy authored and gregkh committed Jul 19, 2023
1 parent 9999a9f commit c94376d
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions drivers/platform/x86/dell/dell-rbtn.c
Original file line number Diff line number Diff line change
Expand Up @@ -395,16 +395,16 @@ static int rbtn_add(struct acpi_device *device)
return -EINVAL;
}

rbtn_data = devm_kzalloc(&device->dev, sizeof(*rbtn_data), GFP_KERNEL);
if (!rbtn_data)
return -ENOMEM;

ret = rbtn_acquire(device, true);
if (ret < 0) {
dev_err(&device->dev, "Cannot enable device\n");
return ret;
}

rbtn_data = devm_kzalloc(&device->dev, sizeof(*rbtn_data), GFP_KERNEL);
if (!rbtn_data)
return -ENOMEM;

rbtn_data->type = type;
device->driver_data = rbtn_data;

Expand All @@ -420,10 +420,12 @@ static int rbtn_add(struct acpi_device *device)
break;
default:
ret = -EINVAL;
break;
}
if (ret)
rbtn_acquire(device, false);

return ret;

}

static int rbtn_remove(struct acpi_device *device)
Expand All @@ -442,7 +444,6 @@ static int rbtn_remove(struct acpi_device *device)
}

rbtn_acquire(device, false);
device->driver_data = NULL;

return 0;
}
Expand Down

0 comments on commit c94376d

Please sign in to comment.