Skip to contentSkip to conversation

remove untouched code in kfifo_in

PATCH In review Wei Yang 5 participants 9 messages Oct 18, 2012 – Oct 23, 2012 3 messages not in the archive Kfifo

lore
Share & tools
lore

Wei Yang

author
#0 lore raw

PATCH 1/1 remove untouched code in kfifo_in

In kfifo_in marco, one piece of code is arounded by if(0). This code in introduced by Stefani Seibold <[email protected]> to suppress a compiler warning. This warning is not there with the upgrade of gcc version.

This patch just remove this code.

---
 include/linux/kfifo.h |    4 ----
 1 files changed, 0 insertions(+), 4 deletions(-)
include/linux/kfifo.h +0 -4
index 10308c6..e7015bb 100644
@@ -512,10 +512,6 @@ __kfifo_uint_must_check_helper( \
 	unsigned long __n = (n); \
 	const size_t __recsize = sizeof(*__tmp->rectype); \
 	struct __kfifo *__kfifo = &__tmp->kfifo; \
-	if (0) { \
-		typeof(__tmp->ptr_const) __dummy __attribute__ ((unused)); \
-		__dummy = (typeof(__buf))NULL; \
-	} \
 	(__recsize) ?\
 	__kfifo_in_r(__kfifo, __buf, __n, __recsize) : \
 	__kfifo_in(__kfifo, __buf, __n); \
Signature · 1 line
1.7.5.4
#1 lore raw
Quoted 5 lines · Wei Yang

In kfifo_in marco, one piece of code is arounded by if(0). This code in introduced by Stefani Seibold <[email protected]> to suppress a compiler warning. This warning is not there with the upgrade of gcc version.

This patch just remove this code.

Are you sure?
This code fragment looks like a compiler bomb to detect type mismatch to me...

Signature · 2 lines
Thanks,
//richard
maintainer
#2 lore raw

Am Freitag, den 19.10.2012, 00:37 +0200 schrieb richard -rw- weinberger:

Quoted 10 lines · Wei Yang
Quoted 5 lines

In kfifo_in marco, one piece of code is arounded by if(0). This code in introduced by Stefani Seibold <[email protected]> to suppress a compiler warning. This warning is not there with the upgrade of gcc version.

This patch just remove this code.

Are you sure?
This code fragment looks like a compiler bomb to detect type mismatch to me...

Yes, you are great! That was the reason why i made this peace of code. So don't remove it!

#3 lore raw
Quoted 11 lines · Stefani Seibold
Quoted 8 lines
Quoted 5 lines

In kfifo_in marco, one piece of code is arounded by if(0). This code in introduced by Stefani Seibold <[email protected]> to suppress a compiler warning. This warning is not there with the upgrade of gcc version.

This patch just remove this code.

Are you sure?
This code fragment looks like a compiler bomb to detect type mismatch to me...

Yes, you are great! That was the reason why i made this peace of code. So don't remove it!

As even you, the author of the code, got confused by it for a while, adding an explanatory comment seems appropriate.

Thanks,

Signature · 2 lines
Jiri Kosina
SUSE Labs
#4 lore raw
Quoted 8 lines · On Fri, 19 Oct 2012 09:34:43 +0200 (CEST) Jiri Kosina <[email protected]> wrote:
Quoted 6 lines · Stefani Seibold
Quoted 6 lines
Quoted 5 lines

In kfifo_in marco, one piece of code is arounded by if(0). This code in introduced by Stefani Seibold <[email protected]> to suppress a compiler warning. This warning is not there with the upgrade of gcc version.

This patch just remove this code.

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

Are you sure?
This code fragment looks like a compiler bomb to detect type mismatch to me...

Yes, you are great! That was the reason why i made this peace of code. So don't remove it!

As even you, the author of the code, got confused by it for a while, adding an explanatory comment seems appropriate.

include/linux/typecheck.h?

A message that is not in the archive (sent off-list or not yet received): [email protected]

#6 lore raw
Quoted 48 lines · Richard Yang
Quoted 14 lines · Andrew Morton
Quoted 11 lines · On Fri, 19 Oct 2012 09:34:43 +0200 (CEST) Jiri Kosina <[email protected]> wrote:
Quoted 9 lines · Stefani Seibold
Quoted 8 lines
Quoted 5 lines

In kfifo_in marco, one piece of code is arounded by if(0). This code in introduced by Stefani Seibold <[email protected]> to suppress a compiler warning. This warning is not there with the upgrade of gcc version.

This patch just remove this code.

Are you sure?
This code fragment looks like a compiler bomb to detect type mismatch to me...

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Yes, you are great! That was the reason why i made this peace of code. So don't remove it!

As even you, the author of the code, got confused by it for a while, adding an explanatory comment seems appropriate.

include/linux/typecheck.h?

Something like this?

From f20c316bf87d5db0816a01705b7869526c0b2363 Mon Sep 17 00:00:00 2001
From: Wei Yang <[email protected]>
Date: Wed, 17 Oct 2012 16:45:49 +0800
Subject: [PATCH] Replace the type check code with typecheck() in kfifo_in

In kfifo_in marco, one piece of code which is arounded by if(0) will check the type of __tmp->ptr_const and __buf. If they are different type, there will output a warning during compiling. This piece of code is not self explaining and a little bit hard to understand.

Based on Andrew Morton's suggestion, this patch replace this with typecheck() which will be easy to understand.

---
 include/linux/kfifo.h |    5 +----
 1 files changed, 1 insertions(+), 4 deletions(-)
include/linux/kfifo.h +0 -0
index 10308c6..b48fe71 100644
@@ -512,10 +512,7 @@ __kfifo_uint_must_check_helper( \
        unsigned long __n = (n); \

include/linux/kfifo.h __kfifo_uint_must_check_helper( \ · line 518

Quoted 10 lines
include/linux/kfifo.h +1 -4
        const size_t __recsize = sizeof(*__tmp->rectype); \
        struct __kfifo *__kfifo = &__tmp->kfifo; \
-       if (0) { \
-               typeof(__tmp->ptr_const) __dummy __attribute__ ((unused)); \
-               __dummy = (typeof(__buf))NULL; \
-       } \
+       typecheck(typeof(__tmp->ptr_const), __buf);\
        (__recsize) ?\
        __kfifo_in_r(__kfifo, __buf, __n, __recsize) : \
        __kfifo_in(__kfifo, __buf, __n); \

What about all the other open coded type checks in that file?

Signature · 2 lines
Thanks,
//richard
#7 lore raw
Quoted 23 lines · On Tue, 23 Oct 2012 21:25:46 +0200 richard -rw- weinberger…
Quoted 23 lines

Subject: [PATCH] Replace the type check code with typecheck() in kfifo_in

In kfifo_in marco, one piece of code which is arounded by if(0) will check the type of __tmp->ptr_const and __buf. If they are different type, there will output a warning during compiling. This piece of code is not self explaining and a little bit hard to understand.

Based on Andrew Morton's suggestion, this patch replace this with typecheck() which will be easy to understand.

---
 include/linux/kfifo.h |    5 +----
 1 files changed, 1 insertions(+), 4 deletions(-)
include/linux/kfifo.h +0 -2
index 10308c6..b48fe71 100644
@@ -512,10 +512,7 @@ __kfifo_uint_must_check_helper( \
        unsigned long __n = (n); \
        const size_t __recsize = sizeof(*__tmp->rectype); \
        struct __kfifo *__kfifo = &__tmp->kfifo; \
-       if (0) { \
-               typeof(__tmp->ptr_const) __dummy __attribute__ ((unused)); \
Quoted 8 lines

include/linux/kfifo.h __kfifo_uint_must_check_helper( \ · line 518

Quoted 6 lines
include/linux/kfifo.h +1 -2
-               __dummy = (typeof(__buf))NULL; \
-       } \
+       typecheck(typeof(__tmp->ptr_const), __buf);\
        (__recsize) ?\
        __kfifo_in_r(__kfifo, __buf, __n, __recsize) : \
        __kfifo_in(__kfifo, __buf, __n); \

What about all the other open coded type checks in that file?

Yes, there are a lot. Searching for "if (0)" finds them.

A message that is not in the archive (sent off-list or not yet received): [email protected]

#9 lore raw
Quoted 14 lines · Richard Yang
Quoted 13 lines · Stefani Seibold

Am Freitag, den 19.10.2012, 00:37 +0200 schrieb richard -rw- weinberger:

Quoted 10 lines · Wei Yang
Quoted 5 lines

In kfifo_in marco, one piece of code is arounded by if(0). This code in introduced by Stefani Seibold <[email protected]> to suppress a compiler warning. This warning is not there with the upgrade of gcc version.

This patch just remove this code.

Are you sure?
This code fragment looks like a compiler bomb to detect type mismatch to me...

Quoted 5 lines
Quoted 2 lines

Yes, you are great! That was the reason why i made this peace of code. So don't remove it!

Thanks for your confirmation.

Hmm, would you give me a hint on how it check the type mismatch?

Here a small hint:
---cut---
struct x {
};
struct y {
};

#define check(a, b) \

({ \
        if (0) { \
                typeof(a) __dummy __attribute__ ((unused)); \
                __dummy = (typeof(b))NULL; \
        } \
})

int main(int argc, char **argv)

{
        struct x _x;
        struct y _y;

        check(&_x, &_x); //okay
        check(&_x, &_y); //will explode with "assignment from

incompatible pointer type"

        return 0;
}

---cut---

Signature · 2 lines
Thanks,
//richard

A message that is not in the archive (sent off-list or not yet received): [email protected]

#11 lore raw
Quoted 1 line · Richard Yang

got it, thanks~

BTW: The surrounding if (0) {} block could be removed in future. I'm sure Stefani added it to suppress a compiler warning. But the typeof() magic has to stay...

Signature · 2 lines
Thanks,
//richard