linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][next] gpio: sim: Fix dereference of free'd pointer config
@ 2021-04-27 10:24 Colin King
  2021-04-27 11:33 ` Bartosz Golaszewski
  0 siblings, 1 reply; 3+ messages in thread
From: Colin King @ 2021-04-27 10:24 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski, Andy Shevchenko, linux-gpio
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

The error return of config->id dereferences the kfree'd object config.
Fix this by using a temporary variable for the id to avoid this issue.

Addresses-Coverity: ("Read from pointer aftyer free")
Fixes: a49d14276ac4 ("gpio: sim: allocate IDA numbers earlier")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/gpio/gpio-sim.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/gpio/gpio-sim.c b/drivers/gpio/gpio-sim.c
index 2e2e6399e453..7bba5783a043 100644
--- a/drivers/gpio/gpio-sim.c
+++ b/drivers/gpio/gpio-sim.c
@@ -751,8 +751,10 @@ gpio_sim_config_make_item(struct config_group *group, const char *name)
 
 	config->id = ida_alloc(&gpio_sim_ida, GFP_KERNEL);
 	if (config->id < 0) {
+		int id = config->id;
+
 		kfree(config);
-		return ERR_PTR(config->id);
+		return ERR_PTR(id);
 	}
 
 	config_item_init_type_name(&config->item, name,
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-04-27 11:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-27 10:24 [PATCH][next] gpio: sim: Fix dereference of free'd pointer config Colin King
2021-04-27 11:33 ` Bartosz Golaszewski
2021-04-27 11:50   ` Colin Ian King

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).