[PATCH 2.6] Remove NULL client checks in rtc8564 driver

From: Jean Delvare
Date: Thu Feb 24 2005 - 16:58:36 EST


Hi Stefan,

Several functions in your rtc8564 driver verify the non-NULLity of the
i2c client that is passed to them. It doesn't seem to be necessary, as I
can't think of any case where these functions could possibly be called
with a NULL i2c client. As a matter of fact, I couldn't find any similar
driver doing such checks.

My attention was brought on this by Coverity's SWAT which correctly
noticed that three of these functions contain explicit or hidden
dereferences of the i2c client pointer *before* the NULL check. I guess
it wasn't a problem because the NULL case cannot happen (unless I miss
something), but this still is confusing code.

Thus I propose the following changes:

Signed-off-by: Jean Delvare <khali@xxxxxxxxxxxx>

--- linux-2.6.11-rc4/drivers/i2c/chips/rtc8564.c.orig Fri Dec 24 22:33:49 2004
+++ linux-2.6.11-rc4/drivers/i2c/chips/rtc8564.c Thu Feb 24 10:56:52 2005
@@ -89,7 +89,7 @@ static int rtc8564_read(struct i2c_clien

_DBG(1, "client=%p, adr=%d, buf=%p, len=%d", client, adr, buf, len);

- if (!buf || !client) {
+ if (!buf) {
ret = -EINVAL;
goto done;
}
@@ -111,7 +111,7 @@ static int rtc8564_write(struct i2c_clie
struct i2c_msg wr;
int i;

- if (!client || !data || len > 15) {
+ if (!data || len > 15) {
ret = -EINVAL;
goto done;
}
@@ -222,7 +222,7 @@ static int rtc8564_get_datetime(struct i

_DBG(1, "client=%p, dt=%p", client, dt);

- if (!dt || !client)
+ if (!dt)
return -EINVAL;

memset(buf, 0, sizeof(buf));
@@ -256,7 +256,7 @@ rtc8564_set_datetime(struct i2c_client *

_DBG(1, "client=%p, dt=%p", client, dt);

- if (!dt || !client)
+ if (!dt)
return -EINVAL;

_DBGRTCTM(2, *dt);
@@ -295,7 +295,7 @@ static int rtc8564_get_ctrl(struct i2c_c
{
struct rtc8564_data *data = i2c_get_clientdata(client);

- if (!ctrl || !client)
+ if (!ctrl)
return -1;

*ctrl = data->ctrl;
@@ -307,7 +307,7 @@ static int rtc8564_set_ctrl(struct i2c_c
struct rtc8564_data *data = i2c_get_clientdata(client);
unsigned char buf[2];

- if (!ctrl || !client)
+ if (!ctrl)
return -1;

buf[0] = *ctrl & 0xff;
@@ -320,7 +320,7 @@
static int rtc8564_read_mem(struct i2c_client *client, struct mem *mem)
{

- if (!mem || !client)
+ if (!mem)
return -EINVAL;

return rtc8564_read(client, mem->loc, mem->data, mem->nr);
@@ -329,7 +329,7 @@
static int rtc8564_write_mem(struct i2c_client *client, struct mem *mem)
{

- if (!mem || !client)
+ if (!mem)
return -EINVAL;

return rtc8564_write(client, mem->loc, mem->data, mem->nr);


Side question: how/when is rtc8564_command called exactly? I think I
understand it has to do with ioctls, but besides that I'm kind of lost.
Can someone explain to me how it works?

Thanks,
--
Jean Delvare
-
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/