Skip to content

Commit 877f0fc

Browse files
committed
Merge pull request #102 from emlid/s805-i2c-deinit-fix
I2C kernel module removal fix
2 parents decbf48 + 7c9d1ef commit 877f0fc

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

drivers/amlogic/i2c/aml_i2c.c

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,6 +1172,8 @@ static int aml_i2c_probe(struct platform_device *pdev)
11721172
if(ret)
11731173
printk(" class register i2c_class fail!\n");
11741174

1175+
platform_set_drvdata(pdev, i2c);
1176+
11751177
return 0;
11761178
}
11771179

@@ -1180,14 +1182,24 @@ static int aml_i2c_probe(struct platform_device *pdev)
11801182
static int aml_i2c_remove(struct platform_device *pdev)
11811183
{
11821184
struct aml_i2c *i2c = platform_get_drvdata(pdev);
1183-
if (i2c->mode == I2C_INTERRUPT_MODE)
1184-
free_irq(i2c->irq, i2c);
1185-
if (i2c->mode == I2C_TIMER_POLLING_MODE)
1186-
hrtimer_cancel(&i2c->aml_i2c_hrtimer);
1187-
mutex_destroy(i2c->lock);
1188-
i2c_del_adapter(&i2c->adap);
1189-
kzfree(i2c);
1190-
i2c= NULL;
1185+
1186+
if (i2c != NULL) {
1187+
if (i2c->mode == I2C_INTERRUPT_MODE) {
1188+
free_irq(i2c->irq, i2c);
1189+
}
1190+
1191+
if (i2c->mode == I2C_TIMER_POLLING_MODE) {
1192+
hrtimer_cancel(&i2c->aml_i2c_hrtimer);
1193+
}
1194+
1195+
mutex_destroy(i2c->lock);
1196+
i2c_del_adapter(&i2c->adap);
1197+
class_unregister(&i2c->cls);
1198+
kzfree(i2c);
1199+
} else {
1200+
printk(KERN_ALERT "[%s]: i2c is NULL\n", __func__);
1201+
}
1202+
11911203
return 0;
11921204
}
11931205

0 commit comments

Comments
 (0)