[patch 09/10] firedtv: fix string comparison and a few sparse warnings

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Stefan Richter
Date: Monday, September 29, 2008 - 10:21 am

Sparse found a bug:
	while ((kv_buf + kv_len - 1) == '\0')
should have been
	while (kv_buf[kv_len - 1] == '\0')
We fix it by a better implementation without a temporary copy.

Also fix sparse warnings of 0 instead of NULL and signedness mismatches.

Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
---
 drivers/media/dvb/firesat/avc_api.c      |   14 +++++++-------
 drivers/media/dvb/firesat/avc_api.h      |    6 +++---
 drivers/media/dvb/firesat/firesat_1394.c |   23 +++++++----------------
 drivers/media/dvb/firesat/firesat_dvb.c  |    2 +-
 4 files changed, 18 insertions(+), 27 deletions(-)

Index: linux/drivers/media/dvb/firesat/firesat_1394.c
===================================================================
--- linux.orig/drivers/media/dvb/firesat/firesat_1394.c
+++ linux/drivers/media/dvb/firesat/firesat_1394.c
@@ -146,8 +146,8 @@ static int firesat_probe(struct device *
 	struct firesat *firesat;
 	unsigned long flags;
 	int kv_len;
+	void *kv_str;
 	int i;
-	char *kv_buf;
 	int err = -ENOMEM;
 
 	firesat = kzalloc(sizeof(*firesat), GFP_KERNEL);
@@ -169,20 +169,12 @@ static int firesat_probe(struct device *
 
 	/* Reading device model from ROM */
 	kv_len = (ud->model_name_kv->value.leaf.len - 2) * sizeof(quadlet_t);
-	kv_buf = kmalloc((sizeof(quadlet_t) * kv_len), GFP_KERNEL);
-	if (!kv_buf)
-		goto fail_free;
-	memcpy(kv_buf, CSR1212_TEXTUAL_DESCRIPTOR_LEAF_DATA(ud->model_name_kv),
-	       kv_len);
-	while ((kv_buf + kv_len - 1) == '\0')
-		kv_len--;
-	kv_buf[kv_len++] = '\0';
-
+	kv_str = CSR1212_TEXTUAL_DESCRIPTOR_LEAF_DATA(ud->model_name_kv);
 	for (i = ARRAY_SIZE(firedtv_model_names); --i;)
-		if (strcmp(kv_buf, firedtv_model_names[i]) == 0)
+		if (strlen(firedtv_model_names[i]) <= kv_len &&
+		    strncmp(kv_str, firedtv_model_names[i], kv_len) == 0)
 			break;
 	firesat->type = i;
-	kfree(kv_buf);
 
 	INIT_LIST_HEAD(&firesat->list);
 	spin_lock_irqsave(&firesat_list_lock, flags);
@@ -191,20 +183,19 @@ static int firesat_probe(struct device *
 
 	err = AVCIdentifySubunit(firesat);
 	if (err)
-		goto fail_unlist;
+		goto fail;
 
 	err = firesat_dvbdev_init(firesat, dev);
 	if (err)
-		goto fail_unlist;
+		goto fail;
 
 	AVCRegisterRemoteControl(firesat);
 	return 0;
 
-fail_unlist:
+fail:
 	spin_lock_irqsave(&firesat_list_lock, flags);
 	list_del(&firesat->list);
 	spin_unlock_irqrestore(&firesat_list_lock, flags);
-fail_free:
 	kfree(firesat);
 	return err;
 }
Index: linux/drivers/media/dvb/firesat/firesat_dvb.c
===================================================================
--- linux.orig/drivers/media/dvb/firesat/firesat_dvb.c
+++ linux/drivers/media/dvb/firesat/firesat_dvb.c
@@ -173,7 +173,7 @@ int firesat_stop_feed(struct dvb_demux_f
 				return -EINVAL;
 
 			demux->pids[dvbdmxfeed->pes_type] |= 0x8000;
-			demux->pesfilter[dvbdmxfeed->pes_type] = 0;
+			demux->pesfilter[dvbdmxfeed->pes_type] = NULL;
 		}
 
 		if (!(dvbdmxfeed->ts_type & TS_DECODER &&
Index: linux/drivers/media/dvb/firesat/avc_api.c
===================================================================
--- linux.orig/drivers/media/dvb/firesat/avc_api.c
+++ linux/drivers/media/dvb/firesat/avc_api.c
@@ -880,7 +880,7 @@ static int get_ca_object_length(AVCRspFr
 	return RspFrm->operand[7];
 }
 
-int avc_ca_app_info(struct firesat *firesat, char *app_info, int *length)
+int avc_ca_app_info(struct firesat *firesat, char *app_info, unsigned int *len)
 {
 	AVCCmdFrm CmdFrm;
 	AVCRspFrm RspFrm;
@@ -912,12 +912,12 @@ int avc_ca_app_info(struct firesat *fire
 	app_info[3] = 6 + RspFrm.operand[pos + 4];
 	app_info[4] = 0x01;
 	memcpy(&app_info[5], &RspFrm.operand[pos], 5 + RspFrm.operand[pos + 4]);
-	*length = app_info[3] + 4;
+	*len = app_info[3] + 4;
 
 	return 0;
 }
 
-int avc_ca_info(struct firesat *firesat, char *app_info, int *length)
+int avc_ca_info(struct firesat *firesat, char *app_info, unsigned int *len)
 {
 	AVCCmdFrm CmdFrm;
 	AVCRspFrm RspFrm;
@@ -948,7 +948,7 @@ int avc_ca_info(struct firesat *firesat,
 	app_info[3] = 2;
 	app_info[4] = app_info[5];
 	app_info[5] = app_info[6];
-	*length = app_info[3] + 4;
+	*len = app_info[3] + 4;
 
 	return 0;
 }
@@ -1178,7 +1178,7 @@ int avc_ca_enter_menu(struct firesat *fi
 	return 0;
 }
 
-int avc_ca_get_mmi(struct firesat *firesat, char *mmi_object, int *length)
+int avc_ca_get_mmi(struct firesat *firesat, char *mmi_object, unsigned int *len)
 {
 	AVCCmdFrm CmdFrm;
 	AVCRspFrm RspFrm;
@@ -1203,8 +1203,8 @@ int avc_ca_get_mmi(struct firesat *fires
 	if(AVCWrite(firesat,&CmdFrm,&RspFrm) < 0)
 		return -EIO;
 
-	*length = get_ca_object_length(&RspFrm);
-	memcpy(mmi_object, &RspFrm.operand[get_ca_object_pos(&RspFrm)], *length);
+	*len = get_ca_object_length(&RspFrm);
+	memcpy(mmi_object, &RspFrm.operand[get_ca_object_pos(&RspFrm)], *len);
 
 	return 0;
 }
Index: linux/drivers/media/dvb/firesat/avc_api.h
===================================================================
--- linux.orig/drivers/media/dvb/firesat/avc_api.h
+++ linux/drivers/media/dvb/firesat/avc_api.h
@@ -434,12 +434,12 @@ int AVCLNBControl(struct firesat *firesa
 void avc_remote_ctrl_work(struct work_struct *work);
 int AVCRegisterRemoteControl(struct firesat *firesat);
 int AVCTuner_Host2Ca(struct firesat *firesat);
-int avc_ca_app_info(struct firesat *firesat, char *app_info, int *length);
-int avc_ca_info(struct firesat *firesat, char *app_info, int *length);
+int avc_ca_app_info(struct firesat *firesat, char *app_info, unsigned int *len);
+int avc_ca_info(struct firesat *firesat, char *app_info, unsigned int *len);
 int avc_ca_reset(struct firesat *firesat);
 int avc_ca_pmt(struct firesat *firesat, char *app_info, int length);
 int avc_ca_get_time_date(struct firesat *firesat, int *interval);
 int avc_ca_enter_menu(struct firesat *firesat);
-int avc_ca_get_mmi(struct firesat *firesat, char *mmi_object, int *length);
+int avc_ca_get_mmi(struct firesat *firesat, char *mmi_object, unsigned int *len);
 
 #endif /* _AVC_API_H */

-- 
Stefan Richter
-=====-==--- =--= ===-=
http://arcgraph.de/sr/

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/devel
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[No subject], , (Wed Dec 31, 5:00 pm)
Dearest Beloved,, Mr. Kunio Uematsu, (Tue Mar 16, 12:52 pm)
Hope to hear from you soon., Christopher Green, (Tue Oct 26, 12:02 pm)
Kick off the Linux Driver Project (again, this time for real), Peter W. Morreale, (Thu Sep 27, 6:21 am)
Kick off the Linux Driver Project (again, this time for real), Peter W. Morreale, (Thu Sep 27, 6:55 am)
Kick off the Linux Driver Project (again, this time for real), Peter W. Morreale, (Thu Sep 27, 7:58 am)
Kick off the Linux Driver Project (again, this time for real), Tomasz Grzegurzko, (Thu Sep 27, 6:40 pm)
JOINT VENTURE., ming yang, (Sun Dec 23, 5:41 am)
broken mailing list, try 47..., Greg KH, (Fri Jan 11, 12:12 pm)
Re: broken mailing list, try 47..., Steven Le Roux, (Sat Jan 12, 11:10 am)
Re: broken mailing list, try 47..., stuart, (Sat Jan 12, 3:56 pm)
Mailing Lists, Tomasz Grzegurzko, (Fri Feb 8, 5:22 pm)
what is the status of this initiative ?, JoJo jojo, (Thu Mar 13, 12:20 am)
Re: what is the status of this initiative ?, Greg KH, (Thu Mar 13, 7:51 am)
Re: what is the status of this initiative ?, Javi Roman, (Thu Mar 13, 10:13 am)
Re: what is the status of this initiative ?, Davide Madrisan, (Thu Mar 13, 10:30 am)
Re: what is the status of this initiative ?, Greg KH, (Thu Mar 13, 10:36 am)
[patch 00/10] firedtv: a few more updates, Stefan Richter, (Mon Sep 29, 10:15 am)
[patch 08/10] firedtv: remove unused struct members, Stefan Richter, (Mon Sep 29, 10:21 am)
[patch 09/10] firedtv: fix string comparison and a few spa ..., Stefan Richter, (Mon Sep 29, 10:21 am)
Re: [patch 00/10] firedtv: a few more updates, Stefan Richter, (Mon Sep 29, 10:46 am)
Gettinng started with Linux drivers, Amit Uttamchandani, (Fri Apr 10, 3:04 pm)
Re: Gettinng started with Linux drivers, Stefan Richter, (Sat Apr 11, 3:00 am)
Re: Gettinng started with Linux drivers, Amit Uttamchandani, (Sun Apr 12, 6:08 pm)
Re: Gettinng started with Linux drivers, Stefan Richter, (Mon Apr 13, 12:39 am)
A tablet driver question, Steven Hunt, (Tue May 19, 9:49 pm)
Re: A tablet driver question, Greg KH, (Tue May 19, 10:12 pm)
Re: A tablet driver question, Steven Hunt, (Tue May 19, 11:16 pm)
Re: A tablet driver question, Jiri Slaby, (Wed May 20, 12:19 am)
Re: A tablet driver question, Steven Hunt, (Wed May 20, 8:58 am)
Re: A tablet driver question, Jiri Slaby, (Wed May 20, 9:24 am)
Re: A tablet driver question, Mohamed Ikbel Boulabiar, (Wed May 20, 9:50 am)
Re: A tablet driver question, Jiri Kosina, (Thu May 21, 1:33 am)