Skip to contentSkip to conversation

2.5.34: IR __FUNCTION__ breakage

DISCUSSION Bob_Tracy 5 participants 11 messages Sep 12, 2002 – Sep 13, 2002

lore
Share & tools
lore

Bob_Tracy

author
#0 lore raw

I've been painstakingly going through all the IR code and fixing up the __FUNCTION__ breakage. One of the not obvious patches is for linux/net/irda/irnet/irnet.h, where string concatenation was fully taken advantage of :-).

The problem lies in statements such as

#define DERROR(dbg, args...) \
	{if(DEBUG_##dbg) \
		printk(KERN_INFO "irnet: " __FUNCTION__ "(): " args);}

where you really want to avoid having any format strings because "args" could legally have one (and probably will). Under the circumstances, one option might be something like

define DERROR(dbg, args...) \
	{if(DEBUG_##dbg){\
		printk(KERN_INFO "irnet: %s(): ", __FUNCTION__);\
		printk(KERN_INFO args);}}

which strikes me as not quite what the author intended, although it should work. Better ideas are welcome, and if a consensus is reached, I'll be happy to submit the full IR __FUNCTION__ patch set against 2.5.34 for inclusion in a later kernel version.

Signature · 4 lines
-----------------------------------------------------------------------
Bob Tracy                   WTO + WIPO = DMCA? http://www.anti-dmca.org
[email protected]
-----------------------------------------------------------------------
#1 lore raw

Hi,

Quoted 7 lines · Bob_Tracy
define DERROR(dbg, args...) \
	{if(DEBUG_##dbg){\
		printk(KERN_INFO "irnet: %s(): ", __FUNCTION__);\
		printk(KERN_INFO args);}}

which strikes me as not quite what the author intended, although it should work.

Why not

#define DERROR(dbg, fmt, args...) \
	do { if (DEBUG_##dbg) \
		printk(KERN_INFO "irnet: %s(): " fmt, __FUNCTION, args); \
	} while(0)

?

Thunder

Signature · 4 lines
--./../...-/. -.--/---/..-/.-./..././.-../..-. .---/..-/.../- .-
--/../-./..-/-/./--..-- ../.----./.-../.-.. --./../...-/. -.--/---/..-
.- -/---/--/---/.-./.-./---/.--/.-.-.-
--./.-/-.../.-./.././.-../.-.-.-
author
#2 lore raw
Quoted 1 line · Thunder from the hill

(good suggestion)

so the revised definition expands from two+ to three+ arguments and becomes

#define DERROR(dbg, fmt, args...) \
    {if(DEBUG_##dbg) \
    	printk(KERN_INFO "irnet: %s(): " fmt, __FUNCTION__, args);}

in the style of the original code. There aren't all that many source files that depend on irnet.h, so this shouldn't be too painful.

TO DO: under linux/net/irda, there's a *lot* of cli(), restore_flags(), save_flags() cleanup work, which I'll happily leave to Jean and/or Dag :-).

Signature · 4 lines
-----------------------------------------------------------------------
Bob Tracy                   WTO + WIPO = DMCA? http://www.anti-dmca.org
[email protected]
-----------------------------------------------------------------------
#3 lore raw
In reply to Thunder from the hill
Quoted 15 lines · Thunder from the hill

Hi,

Quoted 7 lines · Bob_Tracy
define DERROR(dbg, args...) \
	{if(DEBUG_##dbg){\
		printk(KERN_INFO "irnet: %s(): ", __FUNCTION__);\
		printk(KERN_INFO args);}}

which strikes me as not quite what the author intended, although it should work.

Why not

Quoted 8 lines
#define DERROR(dbg, fmt, args...) \
	do { if (DEBUG_##dbg) \
		printk(KERN_INFO "irnet: %s(): " fmt, __FUNCTION, args); \
	} while(0)

?

Thunder

At least for gcc 3.2 this would be better:

#define DERROR(dbg, fmt, args...) \
    do { if (DEBUG_##dbg) \
        printk(KERN_INFO "irnet: %s(): " fmt, __FUNCTION__, ##args); \
    } while(0)

Unfortunately this doesn't work with gcc 2.95.3.

Signature · 2 lines
Andreas Steinmetz
D.O.M. Datenverarbeitung GmbH
#4 lore raw

Hi,

Quoted 8 lines · Andreas Steinmetz

At least for gcc 3.2 this would be better:

#define DERROR(dbg, fmt, args...) \
     do { if (DEBUG_##dbg) \
         printk(KERN_INFO "irnet: %s(): " fmt, __FUNCTION__, ##args); \
     } while(0)

Unfortunately this doesn't work with gcc 2.95.3.

Yepp. As usual, I've forgot the half of it. The second underscores of __FUNCTION__ were victims, just like the double hash before args.

Thunder

Signature · 4 lines
--./../...-/. -.--/---/..-/.-./..././.-../..-. .---/..-/.../- .-
--/../-./..-/-/./--..-- ../.----./.-../.-.. --./../...-/. -.--/---/..-
.- -/---/--/---/.-./.-./---/.--/.-.-.-
--./.-/-.../.-./.././.-../.-.-.-
#5 lore raw
Quoted 11 lines · Thunder from the hill

Hi,

Quoted 7 lines · Andreas Steinmetz

At least for gcc 3.2 this would be better:

#define DERROR(dbg, fmt, args...) \
    do { if (DEBUG_##dbg) \
        printk(KERN_INFO "irnet: %s(): " fmt, __FUNCTION__, ##args); \
    } while(0)

Perhaps a hybrid of the two? :

#define DERROR(dbg, fmt, args...) \

   do { if (DEBUG_##dbg) {                                                \
               printk(KERN_INFO "irnet: %s() : ", __FUNCTION__);          \
               printk(fmt, ## args);                                      \
        }                                                                 \

} while (0)

#6 lore raw

([email protected] removed from cc list as his mta treats (not only) my mails as spam...)

Quoted 13 lines · Ahmed Masud
Quoted 11 lines · Thunder from the hill

Hi,

Quoted 7 lines · Andreas Steinmetz

At least for gcc 3.2 this would be better:

#define DERROR(dbg, fmt, args...) \
    do { if (DEBUG_##dbg) \
        printk(KERN_INFO "irnet: %s(): " fmt, __FUNCTION__, ##args); \
    } while(0)
Quoted 10 lines

Perhaps a hybrid of the two? :

#define DERROR(dbg, fmt, args...)                                          \
   do { if (DEBUG_##dbg) {                                                \
               printk(KERN_INFO "irnet: %s() : ", __FUNCTION__);          \
               printk(fmt, ## args);                                      \
        }                                                                 \
   } while (0)

How about what I did just suggest for smbfs?

#if __GNUC__>=3
#define DERROR(dbg, fmt, args...) \

  do { if (DEBUG_##dbg) \
      printk(KERN_INFO "irnet: %s(): " fmt, __FUNCTION__, ##args); \
  } while(0)
#else
#define DERROR(dbg, args...) \
  {if(DEBUG_##dbg) \
    printk(KERN_INFO "irnet: " __FUNCTION__ "(): " args);}

#endif

gcc 2 versions will be deprecated eventually some time in the future and in between the macro selection by gcc major version should be fair enough.

Signature · 2 lines
Andreas Steinmetz
D.O.M. Datenverarbeitung GmbH
#7 lore raw
In reply to Ahmed Masud

Hi,

Quoted 6 lines · Ahmed Masud
#define DERROR(dbg, fmt, args...)                                          \
    do { if (DEBUG_##dbg) {                                                \
                printk(KERN_INFO "irnet: %s() : ", __FUNCTION__);          \
                printk(fmt, ## args);                                      \
         }                                                                 \
    } while (0)

That's 100% senseless. It gains you nothing, it takes you nothing...

Thunder

Signature · 4 lines
--./../...-/. -.--/---/..-/.-./..././.-../..-. .---/..-/.../- .-
--/../-./..-/-/./--..-- ../.----./.-../.-.. --./../...-/. -.--/---/..-
.- -/---/--/---/.-./.-./---/.--/.-.-.-
--./.-/-.../.-./.././.-../.-.-.-
#8 lore raw
In reply to Andreas Steinmetz

Andreas Steinmetz wrote:-

Quoted 8 lines

At least for gcc 3.2 this would be better:

#define DERROR(dbg, fmt, args...) \
    do { if (DEBUG_##dbg) \
        printk(KERN_INFO "irnet: %s(): " fmt, __FUNCTION__, ##args); \
    } while(0)

Unfortunately this doesn't work with gcc 2.95.3.

I think it might if you put a space after __FUNCTION__ and before the comma.

Neil.

#9 lore raw
Quoted 10 lines · Neil Booth

Andreas Steinmetz wrote:-

Quoted 7 lines

At least for gcc 3.2 this would be better:

#define DERROR(dbg, fmt, args...) \
   do { if (DEBUG_##dbg) \
       printk(KERN_INFO "irnet: %s(): " fmt, __FUNCTION__, ##args); \
   } while(0)
Quoted 8 lines
Quoted 1 line

Unfortunately this doesn't work with gcc 2.95.3.

I think it might if you put a space after __FUNCTION__ and before the comma.

Neil.

Yes, I just verified it does work this way on gcc 2.95.3 though in my opinion it is very prone to errors (typos, ...). Furthermore I don't have any older compilers around for testing this which might still be in use.

Signature · 2 lines
Andreas Steinmetz
D.O.M. Datenverarbeitung GmbH
#10 lore raw

Hi,

Quoted 4 lines · Andreas Steinmetz

Yes, I just verified it does work this way on gcc 2.95.3 though in my opinion it is very prone to errors (typos, ...). Furthermore I don't have any older compilers around for testing this which might still be in use.

gcc 2.92 accepts it.

Thunder

Signature · 4 lines
--./../...-/. -.--/---/..-/.-./..././.-../..-. .---/..-/.../- .-
--/../-./..-/-/./--..-- ../.----./.-../.-.. --./../...-/. -.--/---/..-
.- -/---/--/---/.-./.-./---/.--/.-.-.-
--./.-/-.../.-./.././.-../.-.-.-