Skip to contentSkip to conversation

staging: lustre/lnet: Fix wrong type casting warning generated by sparse

PATCH In review Niranjan Dighe 2 participants 3 messages Feb 13, 2016 – Feb 14, 2016 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: lustre/lnet: Fix wrong type casting warning generated by sparse

Fixed the following warning reported by sparse about typecasting. A userspace pointer was being typecasted by simply (char *) which causes sparse to give the following warning -

warning: cast removes address space of expression

Fixed it by adding __user annotation to the typecasting.

---
 drivers/staging/lustre/lnet/selftest/console.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/lustre/lnet/selftest/console.c +2 -2
index 366211e..64b6a70 100644
@@ -1461,9 +1461,9 @@ lstcon_statrpc_readent(int transop, srpc_msg_t *msg,
 
 	sfwk_stat = (sfw_counters_t __user *)&ent_up->rpe_payload[0];
 	srpc_stat = (srpc_counters_t __user *)
-				      ((char *)sfwk_stat + sizeof(*sfwk_stat));
+				((char __user *)sfwk_stat + sizeof(*sfwk_stat));
 	lnet_stat = (lnet_counters_t __user *)
-				      ((char *)srpc_stat + sizeof(*srpc_stat));
+				((char __user *)srpc_stat + sizeof(*srpc_stat));
 
 	if (copy_to_user(sfwk_stat, &rep->str_fw, sizeof(*sfwk_stat)) ||
 	    copy_to_user(srpc_stat, &rep->str_rpc, sizeof(*srpc_stat)) ||
Signature · 1 line
1.9.1
#1 lore raw

drivers/staging/lustre/lnet/selftest/console.c lstcon_statrpc_readent(int transop, srpc_msg_t *msg, · line 1464

Quoted 10 lines · Niranjan Dighe
drivers/staging/lustre/lnet/selftest/console.c +1 -1
index 366211e..64b6a70 100644
@@ -1461,9 +1461,9 @@ lstcon_statrpc_readent(int transop, srpc_msg_t *msg,
 
 	sfwk_stat = (sfw_counters_t __user *)&ent_up->rpe_payload[0];
 	srpc_stat = (srpc_counters_t __user *)
-				      ((char *)sfwk_stat + sizeof(*sfwk_stat));
+				((char __user *)sfwk_stat + sizeof(*sfwk_stat));

This is uglier than necessary. Do it either like this:

	srpc_stat = (void __user *)sfwk_stat + sizeof(*sfwk_stat);

Or probably it's actually nicer to say:

	srpc_stat = sfwk_stat + 1;

regards,
dan carpenter

#2 lore raw
Quoted 14 lines · Dan Carpenter

drivers/staging/lustre/lnet/selftest/console.c lstcon_statrpc_readent(int transop, srpc_msg_t *msg, · line 1464

Quoted 10 lines · Niranjan Dighe
drivers/staging/lustre/lnet/selftest/console.c +1 -1
index 366211e..64b6a70 100644
@@ -1461,9 +1461,9 @@ lstcon_statrpc_readent(int transop, srpc_msg_t *msg,
 
      sfwk_stat = (sfw_counters_t __user *)&ent_up->rpe_payload[0];
      srpc_stat = (srpc_counters_t __user *)
-                                   ((char *)sfwk_stat + sizeof(*sfwk_stat));
+                             ((char __user *)sfwk_stat + sizeof(*sfwk_stat));

This is uglier than necessary. Do it either like this:

Quoted 9 lines
        srpc_stat = (void __user *)sfwk_stat + sizeof(*sfwk_stat);

Or probably it's actually nicer to say:

        srpc_stat = sfwk_stat + 1;

regards,
dan carpenter

Yes, thanks Dan, I will send out a new patch. Please discard this one.