Re: [PATCH] HID: roccat: Drop cast

2014-06-30 Thread Geert Uytterhoeven
On Sun, Jun 29, 2014 at 8:25 PM, Joe Perches  wrote:
> I think I've seen code in the kernel like
> char *p2 = (void *)p;
> where p is const and p2 is dereferenced and set.

I can imagine there's code like that.

Still hoping for gcc to gain an option to warn about all casts, except in header
files...

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- ge...@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] HID: roccat: Drop cast

2014-06-30 Thread Geert Uytterhoeven
On Sun, Jun 29, 2014 at 8:25 PM, Joe Perches j...@perches.com wrote:
 I think I've seen code in the kernel like
 char *p2 = (void *)p;
 where p is const and p2 is dereferenced and set.

I can imagine there's code like that.

Still hoping for gcc to gain an option to warn about all casts, except in header
files...

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- ge...@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say programmer or something like that.
-- Linus Torvalds
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] HID: roccat: Drop cast

2014-06-29 Thread Joe Perches
On Sun, 2014-06-29 at 18:34 +0200, Julia Lawall wrote:
> On Thu, 26 Jun 2014, Joe Perches wrote:
> > void func(const void * const p)
> > {
> > char *p2 = p;
> > 
> > p2[0] = 1;
> > }
> 
> Is this a real example?

No, it's not.

I think I've seen code in the kernel like
char *p2 = (void *)p;
where p is const and p2 is dereferenced and set.


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] HID: roccat: Drop cast

2014-06-29 Thread Julia Lawall


On Thu, 26 Jun 2014, Joe Perches wrote:

> On Fri, 2014-06-27 at 07:29 +0200, Julia Lawall wrote:
> > On Thu, 26 Jun 2014, Joe Perches wrote:
> > > The cast of a const void * to a void * was odd.
> > > 
> > > Maybe a mechanism to verify appropriateness of
> > > loss of constness for any pointer might be useful.
> > 
> > I tried the following, but didn't find anything interesting:
> > 
> > @disable drop_cast@
> > type T;
> > const T e;
> > @@
> > 
> > * (T)e
> 
> What code does this match?
> Do you have an example match?
> 
> This doesn't find a cast of a void type like:
> 
> void func(const void * const p)
> {
>   char *p2 = p;
> 
>   p2[0] = 1;
> }

Is this a real example?  Because gcc complains about this sort of problem.  
I made a semantic patch that detects this, but since gcc does the same 
thing, it doesn't seem very interesting.  Coccinelle gives a few false 
positives due to lack of type information.

julia
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] HID: roccat: Drop cast

2014-06-29 Thread Julia Lawall


On Thu, 26 Jun 2014, Joe Perches wrote:

 On Fri, 2014-06-27 at 07:29 +0200, Julia Lawall wrote:
  On Thu, 26 Jun 2014, Joe Perches wrote:
   The cast of a const void * to a void * was odd.
   
   Maybe a mechanism to verify appropriateness of
   loss of constness for any pointer might be useful.
  
  I tried the following, but didn't find anything interesting:
  
  @disable drop_cast@
  type T;
  const T e;
  @@
  
  * (T)e
 
 What code does this match?
 Do you have an example match?
 
 This doesn't find a cast of a void type like:
 
 void func(const void * const p)
 {
   char *p2 = p;
 
   p2[0] = 1;
 }

Is this a real example?  Because gcc complains about this sort of problem.  
I made a semantic patch that detects this, but since gcc does the same 
thing, it doesn't seem very interesting.  Coccinelle gives a few false 
positives due to lack of type information.

julia
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] HID: roccat: Drop cast

2014-06-29 Thread Joe Perches
On Sun, 2014-06-29 at 18:34 +0200, Julia Lawall wrote:
 On Thu, 26 Jun 2014, Joe Perches wrote:
  void func(const void * const p)
  {
  char *p2 = p;
  
  p2[0] = 1;
  }
 
 Is this a real example?

No, it's not.

I think I've seen code in the kernel like
char *p2 = (void *)p;
where p is const and p2 is dereferenced and set.


--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] HID: roccat: Drop cast

2014-06-27 Thread Julia Lawall


On Thu, 26 Jun 2014, Joe Perches wrote:

> On Fri, 2014-06-27 at 07:29 +0200, Julia Lawall wrote:
> > On Thu, 26 Jun 2014, Joe Perches wrote:
> > > The cast of a const void * to a void * was odd.
> > >
> > > Maybe a mechanism to verify appropriateness of
> > > loss of constness for any pointer might be useful.
> >
> > I tried the following, but didn't find anything interesting:
> >
> > @disable drop_cast@
> > type T;
> > const T e;
> > @@
> >
> > * (T)e
>
> What code does this match?
> Do you have an example match?
>
> This doesn't find a cast of a void type like:
>
> void func(const void * const p)
> {
>   char *p2 = p;
>
>   p2[0] = 1;
> }

The results are below.  Except in the first case, none are pointer types.
The first case looks very intentional, although if the intention is
needed, perhaps the types should be listed differently.

I was surprised not to get more results.  Maybe there is not enough type
information.  I did use --all-includes but not --recursive-includes, ie
only explicitly mentioned include files are taken into account.

My rule doesn't consider implicit casts like in your example.  I can try
that.

julia


diff -u -p /var/linuxes/linux-next/lib/devres.c /tmp/nothing/lib/devres.c
--- /var/linuxes/linux-next/lib/devres.c
+++ /tmp/nothing/lib/devres.c
@@ -296,7 +296,6 @@ void __iomem *pcim_iomap(struct pci_dev

BUG_ON(bar >= PCIM_IOMAP_MAX);

-   tbl = (void __iomem **)pcim_iomap_table(pdev);
if (!tbl || tbl[bar])   /* duplicate mappings not allowed */
return NULL;

@@ -319,7 +318,6 @@ void pcim_iounmap(struct pci_dev *pdev,

pci_iounmap(pdev, addr);

-   tbl = (void __iomem **)pcim_iomap_table(pdev);
BUG_ON(!tbl);

for (i = 0; i < PCIM_IOMAP_MAX; i++)
diff -u -p /var/linuxes/linux-next/drivers/video/fbdev/smscufx.c 
/tmp/nothing/drivers/video/fbdev/smscufx.c
--- /var/linuxes/linux-next/drivers/video/fbdev/smscufx.c
+++ /tmp/nothing/drivers/video/fbdev/smscufx.c
@@ -976,7 +976,6 @@ static void ufx_dpy_deferred_io(struct f
const int width = dev->info->var.xres;
const int y = (cur->index << PAGE_SHIFT) / (width * 2);
int height = (PAGE_SIZE / (width * 2)) + 1;
-   height = min(height, (int)(dev->info->var.yres - y));

BUG_ON(y >= dev->info->var.yres);
BUG_ON((y + height) > dev->info->var.yres);
diff -u -p /var/linuxes/linux-next/drivers/mtd/chips/jedec_probe.c 
/tmp/nothing/drivers/mtd/chips/jedec_probe.c
--- /var/linuxes/linux-next/drivers/mtd/chips/jedec_probe.c
+++ /tmp/nothing/drivers/mtd/chips/jedec_probe.c
@@ -2027,11 +2027,8 @@ static inline int jedec_match( uint32_t
}
break;
case CFI_DEVICETYPE_X16:
-   mfr = (uint16_t)finfo->mfr_id;
-   id = (uint16_t)finfo->dev_id;
break;
case CFI_DEVICETYPE_X32:
-   mfr = (uint16_t)finfo->mfr_id;
id = (uint32_t)finfo->dev_id;
break;
default:
diff -u -p /var/linuxes/linux-next/drivers/net/wireless/libertas/defs.h 
/tmp/nothing/drivers/net/wireless/libertas/defs.h
--- /var/linuxes/linux-next/drivers/net/wireless/libertas/defs.h
+++ /tmp/nothing/drivers/net/wireless/libertas/defs.h
@@ -105,7 +105,6 @@ static inline void lbs_deb_hex(unsigned
printk("\n");
printk(DRV_NAME " %s: ", prompt);
}
-   printk("%02x ", (u8) * buf);
buf++;
}
printk("\n");
diff -u -p /var/linuxes/linux-next/drivers/media/i2c/tvp5150.c 
/tmp/nothing/drivers/media/i2c/tvp5150.c
--- /var/linuxes/linux-next/drivers/media/i2c/tvp5150.c
+++ /tmp/nothing/drivers/media/i2c/tvp5150.c
@@ -95,7 +95,6 @@ static void dump_reg_range(struct v4l2_s
 {
int i = 0;

-   while (init != (u8)(end + 1)) {
if ((i % max_line) == 0) {
if (i > 0)
printk("\n");
diff -u -p /var/linuxes/linux-next/net/netfilter/ipvs/ip_vs_sync.c 
/tmp/nothing/net/netfilter/ipvs/ip_vs_sync.c
--- /var/linuxes/linux-next/net/netfilter/ipvs/ip_vs_sync.c
+++ /tmp/nothing/net/netfilter/ipvs/ip_vs_sync.c
@@ -1543,7 +1543,6 @@ ip_vs_send_async(struct socket *sock, co
iov.iov_base = (void *)buffer;
iov.iov_len  = length;

-   len = kernel_sendmsg(sock, , , 1, (size_t)(length));

LeaveFunction(7);
return len;
@@ -1575,7 +1574,6 @@ ip_vs_receive(struct socket *sock, char

/* Receive a packet */
iov.iov_base = buffer;
-   iov.iov_len  = (size_t)buflen;

len = kernel_recvmsg(sock, , , 1, buflen, MSG_DONTWAIT);

diff -u -p /var/linuxes/linux-next/net/ipv4/tcp_output.c 
/tmp/nothing/net/ipv4/tcp_output.c
--- /var/linuxes/linux-next/net/ipv4/tcp_output.c
+++ /tmp/nothing/net/ipv4/tcp_output.c
@@ -177,7 

Re: [PATCH] HID: roccat: Drop cast

2014-06-27 Thread Julia Lawall


On Thu, 26 Jun 2014, Joe Perches wrote:

 On Fri, 2014-06-27 at 07:29 +0200, Julia Lawall wrote:
  On Thu, 26 Jun 2014, Joe Perches wrote:
   The cast of a const void * to a void * was odd.
  
   Maybe a mechanism to verify appropriateness of
   loss of constness for any pointer might be useful.
 
  I tried the following, but didn't find anything interesting:
 
  @disable drop_cast@
  type T;
  const T e;
  @@
 
  * (T)e

 What code does this match?
 Do you have an example match?

 This doesn't find a cast of a void type like:

 void func(const void * const p)
 {
   char *p2 = p;

   p2[0] = 1;
 }

The results are below.  Except in the first case, none are pointer types.
The first case looks very intentional, although if the intention is
needed, perhaps the types should be listed differently.

I was surprised not to get more results.  Maybe there is not enough type
information.  I did use --all-includes but not --recursive-includes, ie
only explicitly mentioned include files are taken into account.

My rule doesn't consider implicit casts like in your example.  I can try
that.

julia


diff -u -p /var/linuxes/linux-next/lib/devres.c /tmp/nothing/lib/devres.c
--- /var/linuxes/linux-next/lib/devres.c
+++ /tmp/nothing/lib/devres.c
@@ -296,7 +296,6 @@ void __iomem *pcim_iomap(struct pci_dev

BUG_ON(bar = PCIM_IOMAP_MAX);

-   tbl = (void __iomem **)pcim_iomap_table(pdev);
if (!tbl || tbl[bar])   /* duplicate mappings not allowed */
return NULL;

@@ -319,7 +318,6 @@ void pcim_iounmap(struct pci_dev *pdev,

pci_iounmap(pdev, addr);

-   tbl = (void __iomem **)pcim_iomap_table(pdev);
BUG_ON(!tbl);

for (i = 0; i  PCIM_IOMAP_MAX; i++)
diff -u -p /var/linuxes/linux-next/drivers/video/fbdev/smscufx.c 
/tmp/nothing/drivers/video/fbdev/smscufx.c
--- /var/linuxes/linux-next/drivers/video/fbdev/smscufx.c
+++ /tmp/nothing/drivers/video/fbdev/smscufx.c
@@ -976,7 +976,6 @@ static void ufx_dpy_deferred_io(struct f
const int width = dev-info-var.xres;
const int y = (cur-index  PAGE_SHIFT) / (width * 2);
int height = (PAGE_SIZE / (width * 2)) + 1;
-   height = min(height, (int)(dev-info-var.yres - y));

BUG_ON(y = dev-info-var.yres);
BUG_ON((y + height)  dev-info-var.yres);
diff -u -p /var/linuxes/linux-next/drivers/mtd/chips/jedec_probe.c 
/tmp/nothing/drivers/mtd/chips/jedec_probe.c
--- /var/linuxes/linux-next/drivers/mtd/chips/jedec_probe.c
+++ /tmp/nothing/drivers/mtd/chips/jedec_probe.c
@@ -2027,11 +2027,8 @@ static inline int jedec_match( uint32_t
}
break;
case CFI_DEVICETYPE_X16:
-   mfr = (uint16_t)finfo-mfr_id;
-   id = (uint16_t)finfo-dev_id;
break;
case CFI_DEVICETYPE_X32:
-   mfr = (uint16_t)finfo-mfr_id;
id = (uint32_t)finfo-dev_id;
break;
default:
diff -u -p /var/linuxes/linux-next/drivers/net/wireless/libertas/defs.h 
/tmp/nothing/drivers/net/wireless/libertas/defs.h
--- /var/linuxes/linux-next/drivers/net/wireless/libertas/defs.h
+++ /tmp/nothing/drivers/net/wireless/libertas/defs.h
@@ -105,7 +105,6 @@ static inline void lbs_deb_hex(unsigned
printk(\n);
printk(DRV_NAME  %s: , prompt);
}
-   printk(%02x , (u8) * buf);
buf++;
}
printk(\n);
diff -u -p /var/linuxes/linux-next/drivers/media/i2c/tvp5150.c 
/tmp/nothing/drivers/media/i2c/tvp5150.c
--- /var/linuxes/linux-next/drivers/media/i2c/tvp5150.c
+++ /tmp/nothing/drivers/media/i2c/tvp5150.c
@@ -95,7 +95,6 @@ static void dump_reg_range(struct v4l2_s
 {
int i = 0;

-   while (init != (u8)(end + 1)) {
if ((i % max_line) == 0) {
if (i  0)
printk(\n);
diff -u -p /var/linuxes/linux-next/net/netfilter/ipvs/ip_vs_sync.c 
/tmp/nothing/net/netfilter/ipvs/ip_vs_sync.c
--- /var/linuxes/linux-next/net/netfilter/ipvs/ip_vs_sync.c
+++ /tmp/nothing/net/netfilter/ipvs/ip_vs_sync.c
@@ -1543,7 +1543,6 @@ ip_vs_send_async(struct socket *sock, co
iov.iov_base = (void *)buffer;
iov.iov_len  = length;

-   len = kernel_sendmsg(sock, msg, iov, 1, (size_t)(length));

LeaveFunction(7);
return len;
@@ -1575,7 +1574,6 @@ ip_vs_receive(struct socket *sock, char

/* Receive a packet */
iov.iov_base = buffer;
-   iov.iov_len  = (size_t)buflen;

len = kernel_recvmsg(sock, msg, iov, 1, buflen, MSG_DONTWAIT);

diff -u -p /var/linuxes/linux-next/net/ipv4/tcp_output.c 
/tmp/nothing/net/ipv4/tcp_output.c
--- /var/linuxes/linux-next/net/ipv4/tcp_output.c
+++ /tmp/nothing/net/ipv4/tcp_output.c
@@ -177,7 +177,6 @@ static void tcp_event_data_sent(struct t
/* If 

Re: [PATCH] HID: roccat: Drop cast

2014-06-26 Thread Joe Perches
On Fri, 2014-06-27 at 07:29 +0200, Julia Lawall wrote:
> On Thu, 26 Jun 2014, Joe Perches wrote:
> > The cast of a const void * to a void * was odd.
> > 
> > Maybe a mechanism to verify appropriateness of
> > loss of constness for any pointer might be useful.
> 
> I tried the following, but didn't find anything interesting:
> 
> @disable drop_cast@
> type T;
> const T e;
> @@
> 
> * (T)e

What code does this match?
Do you have an example match?

This doesn't find a cast of a void type like:

void func(const void * const p)
{
char *p2 = p;

p2[0] = 1;
}


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] HID: roccat: Drop cast

2014-06-26 Thread Julia Lawall


On Thu, 26 Jun 2014, Joe Perches wrote:

> On Thu, 2014-06-26 at 22:58 +0530, Himangi Saraogi wrote:
> > This patch removes the cast on data of type void* as it is not needed.
> 
> Hi Himangi
> 
> The cast of a const void * to a void * was odd.
> 
> Maybe a mechanism to verify appropriateness of
> loss of constness for any pointer might be useful.

I tried the following, but didn't find anything interesting:

@disable drop_cast@
type T;
const T e;
@@

* (T)e

julia
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] HID: roccat: Drop cast

2014-06-26 Thread Jiri Kosina
On Thu, 26 Jun 2014, Himangi Saraogi wrote:

> This patch removes the cast on data of type void* as it is not needed.
> The following Coccinelle semantic patch was used for making the change:
> 
> @r@
> expression x;
> void* e;
> type T;
> identifier f;
> @@
> 
> (
>   *((T *)e)
> |
>   ((T *)x)[...]
> |
>   ((T *)x)->f
> |
> - (T *)
>   e
> )
> 
> Signed-off-by: Himangi Saraogi 
> Acked-by: Julia Lawall 
> ---
>  drivers/hid/hid-roccat-lua.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/hid/hid-roccat-lua.c b/drivers/hid/hid-roccat-lua.c
> index 6adc0fa..65e2e76 100644
> --- a/drivers/hid/hid-roccat-lua.c
> +++ b/drivers/hid/hid-roccat-lua.c
> @@ -61,7 +61,7 @@ static ssize_t lua_sysfs_write(struct file *fp, struct 
> kobject *kobj,
>   return -EINVAL;
>  
>   mutex_lock(>lua_lock);
> - retval = roccat_common2_send(usb_dev, command, (void *)buf, real_size);
> + retval = roccat_common2_send(usb_dev, command, buf, real_size);
>   mutex_unlock(>lua_lock);

Applied, thanks.

-- 
Jiri Kosina
SUSE Labs
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] HID: roccat: Drop cast

2014-06-26 Thread Joe Perches
On Thu, 2014-06-26 at 22:58 +0530, Himangi Saraogi wrote:
> This patch removes the cast on data of type void* as it is not needed.

Hi Himangi

The cast of a const void * to a void * was odd.

Maybe a mechanism to verify appropriateness of
loss of constness for any pointer might be useful.


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] HID: roccat: Drop cast

2014-06-26 Thread Himangi Saraogi
This patch removes the cast on data of type void* as it is not needed.
The following Coccinelle semantic patch was used for making the change:

@r@
expression x;
void* e;
type T;
identifier f;
@@

(
  *((T *)e)
|
  ((T *)x)[...]
|
  ((T *)x)->f
|
- (T *)
  e
)

Signed-off-by: Himangi Saraogi 
Acked-by: Julia Lawall 
---
 drivers/hid/hid-roccat-lua.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/hid/hid-roccat-lua.c b/drivers/hid/hid-roccat-lua.c
index 6adc0fa..65e2e76 100644
--- a/drivers/hid/hid-roccat-lua.c
+++ b/drivers/hid/hid-roccat-lua.c
@@ -61,7 +61,7 @@ static ssize_t lua_sysfs_write(struct file *fp, struct 
kobject *kobj,
return -EINVAL;
 
mutex_lock(>lua_lock);
-   retval = roccat_common2_send(usb_dev, command, (void *)buf, real_size);
+   retval = roccat_common2_send(usb_dev, command, buf, real_size);
mutex_unlock(>lua_lock);
 
return retval ? retval : real_size;
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] HID: roccat: Drop cast

2014-06-26 Thread Himangi Saraogi
This patch removes the cast on data of type void* as it is not needed.
The following Coccinelle semantic patch was used for making the change:

@r@
expression x;
void* e;
type T;
identifier f;
@@

(
  *((T *)e)
|
  ((T *)x)[...]
|
  ((T *)x)-f
|
- (T *)
  e
)

Signed-off-by: Himangi Saraogi himangi...@gmail.com
Acked-by: Julia Lawall julia.law...@lip6.fr
---
 drivers/hid/hid-roccat-lua.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/hid/hid-roccat-lua.c b/drivers/hid/hid-roccat-lua.c
index 6adc0fa..65e2e76 100644
--- a/drivers/hid/hid-roccat-lua.c
+++ b/drivers/hid/hid-roccat-lua.c
@@ -61,7 +61,7 @@ static ssize_t lua_sysfs_write(struct file *fp, struct 
kobject *kobj,
return -EINVAL;
 
mutex_lock(lua-lua_lock);
-   retval = roccat_common2_send(usb_dev, command, (void *)buf, real_size);
+   retval = roccat_common2_send(usb_dev, command, buf, real_size);
mutex_unlock(lua-lua_lock);
 
return retval ? retval : real_size;
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] HID: roccat: Drop cast

2014-06-26 Thread Joe Perches
On Thu, 2014-06-26 at 22:58 +0530, Himangi Saraogi wrote:
 This patch removes the cast on data of type void* as it is not needed.

Hi Himangi

The cast of a const void * to a void * was odd.

Maybe a mechanism to verify appropriateness of
loss of constness for any pointer might be useful.


--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] HID: roccat: Drop cast

2014-06-26 Thread Jiri Kosina
On Thu, 26 Jun 2014, Himangi Saraogi wrote:

 This patch removes the cast on data of type void* as it is not needed.
 The following Coccinelle semantic patch was used for making the change:
 
 @r@
 expression x;
 void* e;
 type T;
 identifier f;
 @@
 
 (
   *((T *)e)
 |
   ((T *)x)[...]
 |
   ((T *)x)-f
 |
 - (T *)
   e
 )
 
 Signed-off-by: Himangi Saraogi himangi...@gmail.com
 Acked-by: Julia Lawall julia.law...@lip6.fr
 ---
  drivers/hid/hid-roccat-lua.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
 
 diff --git a/drivers/hid/hid-roccat-lua.c b/drivers/hid/hid-roccat-lua.c
 index 6adc0fa..65e2e76 100644
 --- a/drivers/hid/hid-roccat-lua.c
 +++ b/drivers/hid/hid-roccat-lua.c
 @@ -61,7 +61,7 @@ static ssize_t lua_sysfs_write(struct file *fp, struct 
 kobject *kobj,
   return -EINVAL;
  
   mutex_lock(lua-lua_lock);
 - retval = roccat_common2_send(usb_dev, command, (void *)buf, real_size);
 + retval = roccat_common2_send(usb_dev, command, buf, real_size);
   mutex_unlock(lua-lua_lock);

Applied, thanks.

-- 
Jiri Kosina
SUSE Labs
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] HID: roccat: Drop cast

2014-06-26 Thread Julia Lawall


On Thu, 26 Jun 2014, Joe Perches wrote:

 On Thu, 2014-06-26 at 22:58 +0530, Himangi Saraogi wrote:
  This patch removes the cast on data of type void* as it is not needed.
 
 Hi Himangi
 
 The cast of a const void * to a void * was odd.
 
 Maybe a mechanism to verify appropriateness of
 loss of constness for any pointer might be useful.

I tried the following, but didn't find anything interesting:

@disable drop_cast@
type T;
const T e;
@@

* (T)e

julia
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] HID: roccat: Drop cast

2014-06-26 Thread Joe Perches
On Fri, 2014-06-27 at 07:29 +0200, Julia Lawall wrote:
 On Thu, 26 Jun 2014, Joe Perches wrote:
  The cast of a const void * to a void * was odd.
  
  Maybe a mechanism to verify appropriateness of
  loss of constness for any pointer might be useful.
 
 I tried the following, but didn't find anything interesting:
 
 @disable drop_cast@
 type T;
 const T e;
 @@
 
 * (T)e

What code does this match?
Do you have an example match?

This doesn't find a cast of a void type like:

void func(const void * const p)
{
char *p2 = p;

p2[0] = 1;
}


--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/