From: Jean Delvare <khali@linux-fr.org>
To: Stefan Eletzhofer <Stefan.Eletzhofer@eletztrick.de>
Cc: LKML <linux-kernel@vger.kernel.org>, Greg KH <greg@kroah.com>
Subject: [PATCH 2.6] Remove NULL client checks in rtc8564 driver
Date: Thu, 24 Feb 2005 22:49:57 +0100 [thread overview]
Message-ID: <20050224224957.278cdcd8.khali@linux-fr.org> (raw)
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
next reply other threads:[~2005-02-24 21:54 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-02-24 21:49 Jean Delvare [this message]
2005-02-25 20:07 ` [PATCH 2.6] Remove NULL client checks in rtc8564 driver Greg KH
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20050224224957.278cdcd8.khali@linux-fr.org \
--to=khali@linux-fr.org \
--cc=Stefan.Eletzhofer@eletztrick.de \
--cc=greg@kroah.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.