[PATCH] i2c: fsi: Fix use after free
From: Benjamin Herrenschmidt
Date: Tue Jun 19 2018 - 23:27:32 EST
Signed-off-by: Benjamin Herrenschmidt <benh@xxxxxxxxxxxxxxxxxxx>
---
drivers/i2c/busses/i2c-fsi.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/i2c/busses/i2c-fsi.c b/drivers/i2c/busses/i2c-fsi.c
index 713959b44403..ff69ab6aa79a 100644
--- a/drivers/i2c/busses/i2c-fsi.c
+++ b/drivers/i2c/busses/i2c-fsi.c
@@ -696,9 +696,10 @@ static int fsi_i2c_probe(struct device *dev)
static int fsi_i2c_remove(struct device *dev)
{
struct fsi_i2c_master *i2c = dev_get_drvdata(dev);
- struct fsi_i2c_port *port;
+ struct fsi_i2c_port *port, *tmp;
- list_for_each_entry(port, &i2c->ports, list) {
+ list_for_each_entry_safe(port,tmp, &i2c->ports, list) {
+ list_del(&port->list);
i2c_del_adapter(&port->adapter);
kfree(port);
}