Re: [PATCH] i2c: add sanity check to i2c_put_adapter

From: Sebastian Hesselbarth
Date: Mon Aug 05 2013 - 05:31:52 EST


On 08/05/13 11:00, Wolfram Sang wrote:
On Thu, Aug 01, 2013 at 02:10:46PM +0200, Sebastian Hesselbarth wrote:
i2c_put_adapter dereferences i2c_adapter pointer passed without check
for NULL. This adds a check for non-NULL pointer to allow i2c_put_adapter
called with NULL and behave the same way i2c_release_client does already.

What about using WARN for the NULL case to point out the ref-counting
imbalance?

Wolfram,

I was just adding this to (a) make it consistent with i2c_release_client
and (b) it allows to simplify drivers where you need to release the
adapter during probe failures. But that patch is so small, feel free to
squash in anything you like.

For a more sophisticated (WARN_ON) approach, I suggest to also put one
into i2c_release_client then.

Sebastian


Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@xxxxxxxxx>
---
Cc: Wolfram Sang <wsa@xxxxxxxxxxxxx>
Cc: linux-i2c@xxxxxxxxxxxxxxx
Cc: linux-kernel@xxxxxxxxxxxxxxx
---
drivers/i2c/i2c-core.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index f32ca29..d075df6 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -1825,7 +1825,8 @@ EXPORT_SYMBOL(i2c_get_adapter);

void i2c_put_adapter(struct i2c_adapter *adap)
{
- module_put(adap->owner);
+ if (adap)
+ module_put(adap->owner);
}
EXPORT_SYMBOL(i2c_put_adapter);

--
1.7.10.4


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/