Skip to contentSkip to conversation

Remove NULL client checks in rtc8564 driver

PATCH Applied Jean Delvare 2 participants 2 messages Feb 24, 2005 – Feb 25, 2005

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Remove NULL client checks in rtc8564 driver

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:

drivers/i2c/chips/rtc8564.c renamed from drivers/i2c/chips/rtc8564.c.orig +8 -8
@@ -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,

Signature · 1 line
Jean Delvare
Applied
#1 lore raw
Quoted 8 lines · Jean Delvare

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.

Quoted 7 lines

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