From 0e45dba29ce4c395b6e0dcfd3804d92593b8700c Mon Sep 17 00:00:00 2001 From: David Wen Date: Mon, 4 Nov 2019 16:29:28 +1100 Subject: [PATCH] 4.16 and 4.17 kernel panic fix In Linux kernel 4.16 and 4.17, the function i2c_bit_add_bus attempts to set the clock and data signals on the i2c bus. However, the exanic pointer was not filled in until after the bus was registered, resulting in NULL pointer dereference. This commit fills the exanic pointer into the i2c adapter data before registering the bus to work around the issue. --- modules/exanic/exanic-i2c.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/exanic/exanic-i2c.c b/modules/exanic/exanic-i2c.c index 2bc1bfb..3bd1641 100644 --- a/modules/exanic/exanic-i2c.c +++ b/modules/exanic/exanic-i2c.c @@ -550,6 +550,7 @@ exanic_i2c_bus_register(struct exanic *exanic, int port, data->bit_data.udelay = 20; data->bit_data.timeout = HZ; data->bit_data.data = data; + data->exanic = exanic; /* fill in i2c adapter */ adap->owner = THIS_MODULE; @@ -564,8 +565,6 @@ exanic_i2c_bus_register(struct exanic *exanic, int port, data->xfer_wrapped = adap->algo->master_xfer; exanic_i2c_bit_algo.functionality = adap->algo->functionality; adap->algo = &exanic_i2c_bit_algo; - - data->exanic = exanic; /* add to bus list */ list_add_tail(&data->link, &exanic->i2c_list);