* [PATCH 2.6] Remove NULL client checks in rtc8564 driver
@ 2005-02-24 21:49 Jean Delvare
2005-02-25 20:07 ` Greg KH
0 siblings, 1 reply; 2+ messages in thread
From: Jean Delvare @ 2005-02-24 21:49 UTC (permalink / raw)
To: Stefan Eletzhofer; +Cc: LKML, Greg KH
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@linux-fr.org>
--- 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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH 2.6] Remove NULL client checks in rtc8564 driver
2005-02-24 21:49 [PATCH 2.6] Remove NULL client checks in rtc8564 driver Jean Delvare
@ 2005-02-25 20:07 ` Greg KH
0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2005-02-25 20:07 UTC (permalink / raw)
To: LKML; +Cc: Stefan Eletzhofer
On Thu, Feb 24, 2005 at 10:49:57PM +0100, Jean Delvare wrote:
> 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:
Applied, thanks.
greg k-h
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2005-02-25 20:08 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-02-24 21:49 [PATCH 2.6] Remove NULL client checks in rtc8564 driver Jean Delvare
2005-02-25 20:07 ` Greg KH
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.