2010-08-27 15:36:27

by Yuri Ershov

[permalink] [raw]
Subject: [PATCH 0/2] Accelerometer driver unload

Hello,

I2C part of lis3 accelerometer driver can be unloaded while in use which may
cause kernel oops.

These patches allow to change /dev/freefall file ops owner to prevent driver
unloading while device in use.

Please review.

Best regards,
Yuri

Yuri Kululin (2):
lis3: Add device owner
lis3: Set device owner

drivers/hwmon/lis3lv02d.c | 8 ++++++--
drivers/hwmon/lis3lv02d.h | 2 ++
drivers/hwmon/lis3lv02d_i2c.c | 2 ++
3 files changed, 10 insertions(+), 2 deletions(-)


2010-08-27 15:36:24

by Yuri Ershov

[permalink] [raw]
Subject: [PATCH 2/2] lis3: Set device owner

Set device owner for i2c part.

Signed-off-by: Yuri Kululin <[email protected]>
---
drivers/hwmon/lis3lv02d_i2c.c | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/drivers/hwmon/lis3lv02d_i2c.c b/drivers/hwmon/lis3lv02d_i2c.c
index b2f8bae..1a55bb3 100644
--- a/drivers/hwmon/lis3lv02d_i2c.c
+++ b/drivers/hwmon/lis3lv02d_i2c.c
@@ -129,6 +129,7 @@ static int __devinit lis3lv02d_i2c_probe(struct i2c_client *client,
lis3_dev.reg_ctrl = lis3_reg_ctrl;
lis3_dev.irq = client->irq;
lis3_dev.ac = lis3lv02d_axis_map;
+ lis3_dev.owner = THIS_MODULE;

i2c_set_clientdata(client, &lis3_dev);

@@ -149,6 +150,7 @@ static int __devexit lis3lv02d_i2c_remove(struct i2c_client *client)

lis3lv02d_joystick_disable();
lis3lv02d_remove_fs(&lis3_dev);
+ lis3_dev.owner = NULL;

regulator_bulk_free(ARRAY_SIZE(lis3_dev.regulators),
lis3_dev.regulators);
--
1.7.1.1

2010-08-27 15:36:29

by Yuri Ershov

[permalink] [raw]
Subject: [PATCH 1/2] lis3: Add device owner

Add device owner and change /dev/freefall file operations owner
according to the used driver

Signed-off-by: Yuri Kululin <[email protected]>
---
drivers/hwmon/lis3lv02d.c | 8 ++++++--
drivers/hwmon/lis3lv02d.h | 2 ++
2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/hwmon/lis3lv02d.c b/drivers/hwmon/lis3lv02d.c
index e278f0e..0f1bd36 100644
--- a/drivers/hwmon/lis3lv02d.c
+++ b/drivers/hwmon/lis3lv02d.c
@@ -591,8 +591,7 @@ static int lis3lv02d_misc_fasync(int fd, struct file *file, int on)
return fasync_helper(fd, file, on, &lis3_dev.async_queue);
}

-static const struct file_operations lis3lv02d_misc_fops = {
- .owner = THIS_MODULE,
+static struct file_operations lis3lv02d_misc_fops = {
.llseek = no_llseek,
.read = lis3lv02d_misc_read,
.open = lis3lv02d_misc_open,
@@ -1007,6 +1006,11 @@ int lis3lv02d_init_device(struct lis3lv02d *dev)
goto out;
}

+ if (dev->owner)
+ lis3lv02d_misc_fops.owner = dev->owner;
+ else
+ lis3lv02d_misc_fops.owner = THIS_MODULE;
+
if (misc_register(&lis3lv02d_misc_device))
printk(KERN_ERR DRIVER_NAME ": misc_register failed\n");
out:
diff --git a/drivers/hwmon/lis3lv02d.h b/drivers/hwmon/lis3lv02d.h
index 1f0a66f..e63dd3d 100644
--- a/drivers/hwmon/lis3lv02d.h
+++ b/drivers/hwmon/lis3lv02d.h
@@ -258,6 +258,8 @@ struct lis3lv02d {
unsigned char irq_cfg;
struct lis3lv02d_platform_data *pdata; /* for passing board config */
struct mutex mutex; /* Serialize poll and selftest */
+
+ struct module *owner; /* Device owner */
};

int lis3lv02d_init_device(struct lis3lv02d *lis3);
--
1.7.1.1