Skip to contentSkip to conversation

drivers:input:set driver data to NULL for pcap_keys

PATCH In review Wanlong Gao 5 participants 19 messages Jul 20, 2011 – Jul 26, 2011

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drivers:input:set driver data to NULL for pcap_keys

It's better to set the device's driver data to NULL when remove it.

---
 drivers/input/misc/pcap_keys.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
drivers/input/misc/pcap_keys.c +2 -0
index 99335c2..6c670f5 100644
@@ -114,6 +114,8 @@ static int __devexit pcap_keys_remove(struct platform_device *pdev)
 	input_unregister_device(pcap_keys->input);
 	kfree(pcap_keys);
 
+	platform_set_drvdata(pdev, NULL);
+
 	return 0;
 }
 
Signature · 1 line
1.7.4.1
maintainer
#1 lore raw
Quoted 3 lines · Wanlong Gao

It's better to set the device's driver data to NULL when remove it.

I'd rather have platform devices core clean up this pointer, then we could stop caring about it in all drivers...

Thanks.

Signature · 1 line
Dmitry
#2 lore raw
Quoted 7 lines · Dmitry Torokhov
Quoted 3 lines · Wanlong Gao

It's better to set the device's driver data to NULL when remove it.

I'd rather have platform devices core clean up this pointer, then we could stop caring about it in all drivers...

But the platform devices core just call the method of each own. And don't care about the details like pdata, etc.

Meanwhile, I think the platform core need not care about these details.

and Greg, what do you think about this?

Signature · 3 lines
Thanks
Best Regards
Wanlong Gao
#3 lore raw
Quoted 6 lines · Wanlong Gao
Quoted 5 lines · Dmitry Torokhov
Quoted 3 lines · Wanlong Gao

It's better to set the device's driver data to NULL when remove it.

Quoted 8 lines
Quoted 2 lines

I'd rather have platform devices core clean up this pointer, then we could stop caring about it in all drivers...

But the platform devices core just call the method of each own. And don't care about the details like pdata, etc.

Meanwhile, I think the platform core need not care about these details.

and Greg, what do you think about this?

I don't understand what you are asking me.

#4 lore raw
Quoted 9 lines · Greg KH
Quoted 8 lines · Wanlong Gao
Quoted 7 lines · Dmitry Torokhov
Quoted 3 lines · Wanlong Gao

It's better to set the device's driver data to NULL when remove it.

I'd rather have platform devices core clean up this pointer, then we could stop caring about it in all drivers...

Quoted 8 lines
Quoted 6 lines

But the platform devices core just call the method of each own. And don't care about the details like pdata, etc.

Meanwhile, I think the platform core need not care about these details.

and Greg, what do you think about this?

I don't understand what you are asking me.

Sorry, that's below:
firt for this patch:

Quoted 15 lines

It's better to set the device's driver data to NULL when remove it.

---
 drivers/input/misc/pcap_keys.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
drivers/input/misc/pcap_keys.c +0 -0
index 99335c2..6c670f5 100644

drivers/input/misc/pcap_keys.c static int __devexit pcap_keys_remove(struct · line 121

Quoted 8 lines
drivers/input/misc/pcap_keys.c +2 -0
@@ -114,6 +114,8 @@ static int __devexit pcap_keys_remove(struct
 platform_device *pdev)
        input_unregister_device(pcap_keys->input);
        kfree(pcap_keys);
 
+       platform_set_drvdata(pdev, NULL);
+
        return 0;
 }

then, Dmitry said that:

Quoted 3 lines

I'd rather have platform devices core clean up this pointer, then we could stop caring about it in all drivers...

Quoted 8 lines · then I

But the platform devices core just call the method of each own. And don't care about the details like pdata, etc.

Meanwhile, I think the platform core need not care about these details.

and Greg, what do you think about this?

this is the thread, Greg, understand now?

For short, it's all about the platform driver data. Since many drivers set the platform driver data to NULL when it is removed, then Dmitry think it should be done in the platform driver core instead. So, I asked you for this.

It's clear now?

Thanks a lot

maintainer
#5 lore raw
Quoted 14 lines · Wanlong Gao
Quoted 5 lines
Quoted 1 line · Dmitry Torokhov

I'd rather have platform devices core clean up this pointer, then we could stop caring about it in all drivers...

Quoted 6 lines · then I

But the platform devices core just call the method of each own. And don't care about the details like pdata, etc.

Meanwhile, I think the platform core need not care about these details.

Quoted 7 lines
Quoted 2 lines

and Greg, what do you think about this?

this is the thread, Greg, understand now?

For short, it's all about the platform driver data. Since many drivers set the platform driver data to NULL when it is removed, then Dmitry think it should be done in the platform driver core instead.

Right, like i2c bus we could just have platform core clean up platform drvdata pointer after calling ->remove() and also if ->probe() errors out.

Then individual drivers do not have to care about cleaning up this pointer.

Thanks.

Signature · 1 line
Dmitry
#6 lore raw
Quoted 3 lines · Dmitry Torokhov

Right, like i2c bus we could just have platform core clean up platform drvdata pointer after calling ->remove() and also if ->probe() errors out.

I2C doesn't do this (at least not any more).

Quoted 2 lines

Then individual drivers do not have to care about cleaning up this pointer.

They don't have to worry about it anyway, the only thing that is allowed to use the pointer is a currently bound driver and it's only allowed to rely on is that while it's bound it'll get back the same driver_data that it put in.

maintainer
#7 lore raw
Quoted 8 lines · Mark Brown
Quoted 3 lines · Dmitry Torokhov

Right, like i2c bus we could just have platform core clean up platform drvdata pointer after calling ->remove() and also if ->probe() errors out.

I2C doesn't do this (at least not any more).

Sure does. See drivers/i2c/i2c-core.c::i2c_device_probe() and i2c_device_remove().

Quoted 7 lines
Quoted 2 lines

Then individual drivers do not have to care about cleaning up this pointer.

They don't have to worry about it anyway, the only thing that is allowed to use the pointer is a currently bound driver and it's only allowed to rely on is that while it's bound it'll get back the same driver_data that it put in.

Right, except that some people trying to use this pointers to pass platform data to the driver... Resetting the pointer to NULL on unbind will hopefully show them their mistake.

Signature · 1 line
Dmitry
#8 lore raw
Quoted 7 lines · Dmitry Torokhov
Quoted 6 lines · Mark Brown
Quoted 3 lines · Dmitry Torokhov

Right, like i2c bus we could just have platform core clean up platform drvdata pointer after calling ->remove() and also if ->probe() errors out.

Quoted 5 lines
Quoted 2 lines

I2C doesn't do this (at least not any more).

Sure does. See drivers/i2c/i2c-core.c::i2c_device_probe() and i2c_device_remove().

Yeah, I see it. Sure i2c does.
Let the Core to do the pointer's clean up is very good idea.

So, Dmitry, do you means this ?

---
 drivers/base/platform.c |   30 ++++++++++++++++++++++++++++--
 1 files changed, 28 insertions(+), 2 deletions(-)
drivers/base/platform.c +28 -2
index 6040717..349e71b 100644
@@ -405,8 +405,21 @@ static int platform_drv_probe(struct device *_dev)
 {
 	struct platform_driver *drv = to_platform_driver(_dev->driver);
 	struct platform_device *dev = to_platform_device(_dev);
+	int status;
 
-	return drv->probe(dev);
+	if (!dev)
+		return 0;
+
+	if (!drv->probe)
+		return -ENODEV;
+
+	dev_dbg(_dev, "probe\n");
+
+	status = drv->probe(dev);
+	if (status)
+		platform_set_drvdata(dev, NULL);
+
+	return status;
 }
 
 static int platform_drv_probe_fail(struct device *_dev)
@@ -418,8 +431,21 @@ static int platform_drv_remove(struct device *_dev)
 {
 	struct platform_driver *drv = to_platform_driver(_dev->driver);
 	struct platform_device *dev = to_platform_device(_dev);
+	int status;
+
+	if (!dev)
+		return 0;
+
+	if (drv->remove) {
+		dev_dbg(_dev, "remove\n");
+		status = drv->remove(dev);
+	} else {
+		status = 0;
+	}
+	if (status == 0)
+		platform_set_drvdata(dev, NULL);
 
-	return drv->remove(dev);
+	return status;
 }
 
 static void platform_drv_shutdown(struct device *_dev)
Signature · 8 lines
1.7.6



-- 
Thanks
Best Regards
Wanlong Gao
#9 lore raw
Quoted 8 lines · Wanlong Gao
Quoted 7 lines · Dmitry Torokhov
Quoted 6 lines · Mark Brown
Quoted 3 lines · Dmitry Torokhov

Right, like i2c bus we could just have platform core clean up platform drvdata pointer after calling ->remove() and also if ->probe() errors out.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

I2C doesn't do this (at least not any more).

Sure does. See drivers/i2c/i2c-core.c::i2c_device_probe() and i2c_device_remove().

Yeah, I see it. Sure i2c does.
Let the Core to do the pointer's clean up is very good idea.

No it isn't.

Quoted 12 lines

So, Dmitry, do you means this ?

---
 drivers/base/platform.c |   30 ++++++++++++++++++++++++++++--
 1 files changed, 28 insertions(+), 2 deletions(-)
drivers/base/platform.c +0 -0
index 6040717..349e71b 100644

drivers/base/platform.c static int platform_drv_probe(struct device *_dev) · line 411

Quoted 8 lines
drivers/base/platform.c +3 -1
@@ -405,8 +405,21 @@ static int platform_drv_probe(struct device *_dev)
 {
 	struct platform_driver *drv = to_platform_driver(_dev->driver);
 	struct platform_device *dev = to_platform_device(_dev);
+	int status;
 
-	return drv->probe(dev);
+	if (!dev)
+		return 0;

When would dev ever be NULL? Wouldn't that be an error?

drivers/base/platform.c static int platform_drv_probe(struct device *_dev) · line 414

Quoted 3 lines
drivers/base/platform.c +3 -0
+
+	if (!drv->probe)
+		return -ENODEV;

That's not a valid error for this. And when would probe ever be NULL?

drivers/base/platform.c static int platform_drv_probe(struct device *_dev) · line 416

Quoted 2 lines
drivers/base/platform.c +2 -0
+
+	dev_dbg(_dev, "probe\n");

Why add this noise?

drivers/base/platform.c static int platform_drv_probe(struct device *_dev) · line 420

Quoted 4 lines
drivers/base/platform.c +4 -0
+
+	status = drv->probe(dev);
+	if (status)
+		platform_set_drvdata(dev, NULL);

No, not ok.

drivers/base/platform.c static int platform_drv_remove(struct device *_dev) · line 437

Quoted 13 lines
drivers/base/platform.c +6 -0
+
+	return status;
 }
 
 static int platform_drv_probe_fail(struct device *_dev)
@@ -418,8 +431,21 @@ static int platform_drv_remove(struct device *_dev)
 {
 	struct platform_driver *drv = to_platform_driver(_dev->driver);
 	struct platform_device *dev = to_platform_device(_dev);
+	int status;
+
+	if (!dev)
+		return 0;

Again, when would that ever happen?

drivers/base/platform.c static int platform_drv_remove(struct device *_dev) · line 444

Quoted 7 lines
drivers/base/platform.c +7 -0
+
+	if (drv->remove) {
+		dev_dbg(_dev, "remove\n");
+		status = drv->remove(dev);
+	} else {
+		status = 0;
+	}

Again, why would remove ever be NULL?

This whole thing isn't needed at all.

greg k-h

#10 lore raw
Quoted 10 lines · Greg KH

drivers/base/platform.c static int platform_drv_remove(struct device *_dev) · line 444

Quoted 7 lines
drivers/base/platform.c +7 -0
+
+	if (drv->remove) {
+		dev_dbg(_dev, "remove\n");
+		status = drv->remove(dev);
+	} else {
+		status = 0;
+	}

Again, why would remove ever be NULL?

Quoted 3 lines

This whole thing isn't needed at all.

greg k-h

Yeah, I see.

But Greg, why does i2c-core do this?
like:drivers/i2c/i2c-core.c:
static int i2c_device_remove(struct device *dev)

{
	struct i2c_client	*client = i2c_verify_client(dev);
	struct i2c_driver	*driver;
	int			status;

	if (!client || !dev->driver)
		return 0;

	driver = to_i2c_driver(dev->driver);
	if (driver->remove) {
		dev_dbg(dev, "remove\n");
		status = driver->remove(client);
	} else {
		dev->driver = NULL;
		status = 0;
	}
	if (status == 0) {
		client->driver = NULL;
		i2c_set_clientdata(client, NULL);
	}
	return status;
}

And now, I'm in a fog, can you clear me/us ?

Signature · 3 lines
Thanks
Best Regards
Wanlong Gao
#11 lore raw
Quoted 12 lines · Wanlong Gao
Quoted 10 lines · Greg KH

drivers/base/platform.c static int platform_drv_remove(struct device *_dev) · line 444

Quoted 7 lines
drivers/base/platform.c +7 -0
+
+	if (drv->remove) {
+		dev_dbg(_dev, "remove\n");
+		status = drv->remove(dev);
+	} else {
+		status = 0;
+	}

Again, why would remove ever be NULL?

Quoted 7 lines
Quoted 3 lines

This whole thing isn't needed at all.

greg k-h

Yeah, I see.

But Greg, why does i2c-core do this?
like:drivers/i2c/i2c-core.c:

The i2c core has different requirements than the driver core does, right? They are two totally different things, please don't assume that the rules for one are the same for the other.

greg k-h

#12 lore raw
Quoted 18 lines · Greg KH
Quoted 17 lines · Wanlong Gao
Quoted 10 lines · Greg KH

drivers/base/platform.c static int platform_drv_remove(struct device *_dev) · line 444

Quoted 7 lines
drivers/base/platform.c +7 -0
+
+	if (drv->remove) {
+		dev_dbg(_dev, "remove\n");
+		status = drv->remove(dev);
+	} else {
+		status = 0;
+	}

Again, why would remove ever be NULL?

Quoted 3 lines

This whole thing isn't needed at all.

greg k-h

Yeah, I see.

Quoted 9 lines
Quoted 2 lines

But Greg, why does i2c-core do this?
like:drivers/i2c/i2c-core.c:

The i2c core has different requirements than the driver core does, right? They are two totally different things, please don't assume that the rules for one are the same for the other.

greg k-h

Hmm...They are totally different things, maybe I see..

Signature · 3 lines
Thanks
Best Regards
Wanlong Gao
maintainer
#13 lore raw
Quoted 22 lines · Wanlong Gao
Quoted 21 lines · Greg KH
Quoted 19 lines · Wanlong Gao
Quoted 10 lines · Greg KH

drivers/base/platform.c static int platform_drv_remove(struct device *_dev) · line 444

Quoted 7 lines
drivers/base/platform.c +7 -0
+
+	if (drv->remove) {
+		dev_dbg(_dev, "remove\n");
+		status = drv->remove(dev);
+	} else {
+		status = 0;
+	}

Again, why would remove ever be NULL?

Quoted 3 lines

This whole thing isn't needed at all.

greg k-h

Yeah, I see.

But Greg, why does i2c-core do this?
like:drivers/i2c/i2c-core.c:

Quoted 7 lines
Quoted 6 lines

The i2c core has different requirements than the driver core does, right? They are two totally different things, please don't assume that the rules for one are the same for the other.

greg k-h

Hmm...They are totally different things, maybe I see..

Still, it would make sense to clean up platform device's drvdata pointer, so that every platform driver out there does not have to do it on its own.

Signature · 1 line
Dmitry
#14 lore raw
Quoted 27 lines · Dmitry Torokhov
Quoted 26 lines · Wanlong Gao
Quoted 25 lines · Greg KH
Quoted 12 lines · Wanlong Gao
Quoted 10 lines · Greg KH

drivers/base/platform.c static int platform_drv_remove(struct device *_dev) · line 444

Quoted 7 lines
drivers/base/platform.c +7 -0
+
+	if (drv->remove) {
+		dev_dbg(_dev, "remove\n");
+		status = drv->remove(dev);
+	} else {
+		status = 0;
+	}

Again, why would remove ever be NULL?

Quoted 7 lines
Quoted 3 lines

This whole thing isn't needed at all.

greg k-h

Yeah, I see.

But Greg, why does i2c-core do this?
like:drivers/i2c/i2c-core.c:

The i2c core has different requirements than the driver core does, right? They are two totally different things, please don't assume that the rules for one are the same for the other.

Quoted 7 lines
Quoted 3 lines
Quoted 2 lines

greg k-h

Hmm...They are totally different things, maybe I see..

Still, it would make sense to clean up platform device's drvdata pointer, so that every platform driver out there does not have to do it on its own.

Again, it shouldn't need to be "cleaned" up, as no one relies on it being there.

greg k-h

maintainer
#15 lore raw
Quoted 30 lines · Greg KH
Quoted 29 lines · Dmitry Torokhov
Quoted 28 lines · Wanlong Gao
Quoted 27 lines · Greg KH
Quoted 12 lines · Wanlong Gao
Quoted 10 lines · Greg KH

Review

Quoted 7 lines
(quoted diff) +7 -0
+
+	if (drv->remove) {
+		dev_dbg(_dev, "remove\n");
+		status = drv->remove(dev);
+	} else {
+		status = 0;
+	}

Again, why would remove ever be NULL?

Quoted 7 lines
Quoted 3 lines

This whole thing isn't needed at all.

greg k-h

Yeah, I see.

But Greg, why does i2c-core do this?
like:drivers/i2c/i2c-core.c:

The i2c core has different requirements than the driver core does, right? They are two totally different things, please don't assume that the rules for one are the same for the other.

greg k-h

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Hmm...They are totally different things, maybe I see..

Still, it would make sense to clean up platform device's drvdata pointer, so that every platform driver out there does not have to do it on its own.

Again, it shouldn't need to be "cleaned" up, as no one relies on it being there.

No one should rely on it being there however I came across quite a few MFD patches that tried passing parent's data in that pointer. Hopefully they are all cleaned now but we getting new drivers all the time...

If we had it in the platform bus code such uses would break even before we get such drivers and we won't have to deal with them.

Thanks.

Signature · 1 line
Dmitry
#16 lore raw
In reply to Greg KH
Quoted 6 lines · Greg KH
Quoted 4 lines · Wanlong Gao
Quoted 2 lines · Dmitry Torokhov

I'd rather have platform devices core clean up this pointer, then we could stop caring about it in all drivers...

Quoted 8 lines
Quoted 6 lines

But the platform devices core just call the method of each own. And don't care about the details like pdata, etc.

Meanwhile, I think the platform core need not care about these details.

and Greg, what do you think about this?

I don't understand what you are asking me.

They're asking if drivers should set driver_data to NULL while unbinding, which always struck me as a waste of time given that nothing except a currently bound driver should be using driver_data.

#17 lore raw
Quoted 12 lines · Mark Brown
Quoted 10 lines · Greg KH
Quoted 9 lines · Wanlong Gao
Quoted 2 lines · Dmitry Torokhov

I'd rather have platform devices core clean up this pointer, then we could stop caring about it in all drivers...

But the platform devices core just call the method of each own. And don't care about the details like pdata, etc.

Meanwhile, I think the platform core need not care about these details.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

and Greg, what do you think about this?

I don't understand what you are asking me.

They're asking if drivers should set driver_data to NULL while unbinding, which always struck me as a waste of time given that nothing except a currently bound driver should be using driver_data.

Yeah, it's not needed, as nothing should rely on that. However it's also not hurting anything either.

greg k-h

#18 lore raw
Quoted 8 lines · Greg KH
Quoted 3 lines · Mark Brown

They're asking if drivers should set driver_data to NULL while unbinding, which always struck me as a waste of time given that nothing except a currently bound driver should be using driver_data.

Yeah, it's not needed, as nothing should rely on that. However it's also not hurting anything either.

Every time I see it it always sets off a red flag, partly because we shouldn't need to bother at all and partly because to the extent it's valuable it's not something we should be doing on a driver by driver or even subsystem by subsystem basis.