Skip to contentSkip to conversation

staging: fwserial: replace 'a' with '(a)' to avoid precedence issues

PATCH In review Arushi Singhal 5 participants 6 messages Feb 14, 2017 – Feb 15, 2017 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: fwserial: replace 'a' with '(a)' to avoid precedence issues

Macro argument 'a' may be better as '(a)' to avoid precedence issues as reported by checkpatch.pl

---
 drivers/staging/fwserial/fwserial.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/fwserial/fwserial.c +1 -1
index 41a49c8194e5..bdfc0a8c7af3 100644
@@ -98,7 +98,7 @@ struct fwtty_transaction {
 	};
 };
 
-#define to_device(a, b)			(a->b)
+#define to_device((a), b)			(a->b)
 #define fwtty_err(p, fmt, ...)						\
 	dev_err(to_device(p, device), fmt, ##__VA_ARGS__)
 #define fwtty_info(p, fmt, ...)						\
Signature · 1 line
2.11.0
maintainer
#1 lore raw
Quoted 13 lines · Arushi Singhal

Macro argument 'a' may be better as '(a)' to avoid precedence issues as reported by checkpatch.pl

---
 drivers/staging/fwserial/fwserial.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/fwserial/fwserial.c +0 -0
index 41a49c8194e5..bdfc0a8c7af3 100644

drivers/staging/fwserial/fwserial.c struct fwtty_transaction { · line 101

Quoted 5 lines
drivers/staging/fwserial/fwserial.c +1 -1
@@ -98,7 +98,7 @@ struct fwtty_transaction {
 	};
 };
 
-#define to_device(a, b)			(a->b)
+#define to_device((a), b)			(a->b)

Really? Why do we even have this macro at all? Can it just be removed?

thanks,

greg k-h

#2 lore raw
Quoted 17 lines · Greg KH
Quoted 16 lines · Arushi Singhal

Macro argument 'a' may be better as '(a)' to avoid precedence issues as reported by checkpatch.pl

---
 drivers/staging/fwserial/fwserial.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/fwserial/fwserial.c +0 -0
index 41a49c8194e5..bdfc0a8c7af3 100644
@@ -98,7 +98,7 @@ struct fwtty_transaction {
      };
 };
 
Quoted 4 lines

drivers/staging/fwserial/fwserial.c struct fwtty_transaction { · line 101

Quoted 2 lines
drivers/staging/fwserial/fwserial.c +1 -1
-#define to_device(a, b)                      (a->b)
+#define to_device((a), b)                    (a->b)

Really?

Actually compiling files should be a requirement for submitting patches, cfr. the response from kbuild test report.
The parentheses should be added to the second "a" instead ;-)

Quoted 1 line

Why do we even have this macro at all? Can it just be removed?

Definitely. Would be much easier to read.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

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

#3 lore raw
Quoted 23 lines · Geert Uytterhoeven
Quoted 17 lines · Greg KH
Quoted 16 lines · Arushi Singhal

Macro argument 'a' may be better as '(a)' to avoid precedence issues as reported by checkpatch.pl

---
 drivers/staging/fwserial/fwserial.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/fwserial/fwserial.c +0 -0
index 41a49c8194e5..bdfc0a8c7af3 100644
@@ -98,7 +98,7 @@ struct fwtty_transaction {
      };
 };
 
Quoted 4 lines

drivers/staging/fwserial/fwserial.c struct fwtty_transaction { · line 101

Quoted 2 lines
drivers/staging/fwserial/fwserial.c +1 -1
-#define to_device(a, b)                      (a->b)
+#define to_device((a), b)                    (a->b)

Really?

Quoted 7 lines

Actually compiling files should be a requirement for submitting patches, cfr. the response from kbuild test report.
The parentheses should be added to the second "a" instead ;-)

Quoted 1 line

Why do we even have this macro at all? Can it just be removed?

Definitely. Would be much easier to read.

The use of & in some of the fwtty_<level> macro uses suggest it would be easier to read if the fwtty_macros were removed altogether and simply converted to their dev_<level> equivalents.

$ git grep -E -w -n "fwtty_(err|info|notice|warn|dbg|err_ratelimited)"| cat
drivers/staging/fwserial/fwserial.c:101:#define fwtty_err(p, fmt, ...)						\
drivers/staging/fwserial/fwserial.c:103:#define fwtty_info(p, fmt, ...)						\
drivers/staging/fwserial/fwserial.c:105:#define fwtty_notice(p, fmt, ...)					\
drivers/staging/fwserial/fwserial.c:107:#define fwtty_dbg(p, fmt, ...)						\
drivers/staging/fwserial/fwserial.c:109:#define fwtty_err_ratelimited(p, fmt, ...)				\
drivers/staging/fwserial/fwserial.c:121:		fwtty_dbg(port, "short write: avail:%d req:%d wrote:%d\n",
drivers/staging/fwserial/fwserial.c:200:		fwtty_err_ratelimited(port, "card busy\n");
drivers/staging/fwserial/fwserial.c:203:		fwtty_err_ratelimited(port, "bad unit addr or write length\n");
drivers/staging/fwserial/fwserial.c:206:		fwtty_err_ratelimited(port, "failed rx\n");
drivers/staging/fwserial/fwserial.c:209:		fwtty_err_ratelimited(port, "missing ack\n");
drivers/staging/fwserial/fwserial.c:212:		fwtty_err_ratelimited(port, "remote busy\n");
drivers/staging/fwserial/fwserial.c:215:		fwtty_err_ratelimited(port, "failed tx: %d\n", rcode);
drivers/staging/fwserial/fwserial.c:289:	fwtty_dbg(port, "fifo len: %d avail: %d\n", len, avail);
drivers/staging/fwserial/fwserial.c:326:	fwtty_dbg(port, "status: %x delta: %x\n", status, delta);
drivers/staging/fwserial/fwserial.c:522:	fwtty_dbg(port, "sending %d brks\n", n);
drivers/staging/fwserial/fwserial.c:546:	fwtty_dbg(port, "%d\n", n);
drivers/staging/fwserial/fwserial.c:586:		fwtty_err_ratelimited(port, "flip buffer overrun\n");
drivers/staging/fwserial/fwserial.c:629:		fwtty_err_ratelimited(port, "ignoring unauthenticated data\n");
drivers/staging/fwserial/fwserial.c:686:	fwtty_dbg(port, "rcode: %d\n", rcode);
drivers/staging/fwserial/fwserial.c:749:		fwtty_dbg(port, "out: %u rem: %d\n", txn->dma_pended.len, n);
drivers/staging/fwserial/fwserial.c:759:				fwtty_err_ratelimited(port, "fifo err: %d\n",
drivers/staging/fwserial/fwserial.c:819:	fwtty_dbg(port, "%02x\n", ch);
drivers/staging/fwserial/fwserial.c:904:	fwtty_dbg(port, "on/off: %d\n", on);
drivers/staging/fwserial/fwserial.c:932:	fwtty_dbg(port, "%d\n", rc);
drivers/staging/fwserial/fwserial.c:1110:	fwtty_dbg(port, "%d\n", c);
drivers/staging/fwserial/fwserial.c:1137:	fwtty_dbg(port, "%d\n", n);
drivers/staging/fwserial/fwserial.c:1151:	fwtty_dbg(port, "%d\n", n);
drivers/staging/fwserial/fwserial.c:1160:	fwtty_dbg(port, "%02x\n", ch);
drivers/staging/fwserial/fwserial.c:1187:	fwtty_dbg(port, "CRTSCTS: %d\n", C_CRTSCTS(tty) != 0);
drivers/staging/fwserial/fwserial.c:1341:	fwtty_dbg(port, "%d\n", state);
drivers/staging/fwserial/fwserial.c:1378:	fwtty_dbg(port, "%x\n", tiocm);
drivers/staging/fwserial/fwserial.c:1388:	fwtty_dbg(port, "set: %x clear: %x\n", set, clear);
drivers/staging/fwserial/fwserial.c:1700:	fwtty_info(&peer->unit, "peer (guid:%016llx) connected on %s\n",
drivers/staging/fwserial/fwserial.c:1722:			fwtty_dbg(&peer->unit, "mgmt write error: %d\n", rcode);
drivers/staging/fwserial/fwserial.c:1844:		fwtty_err(&peer->unit, "avail ports in use\n");
drivers/staging/fwserial/fwserial.c:1982:		fwtty_err(card, "unknown card (guid %016llx)\n",
drivers/staging/fwserial/fwserial.c:2012:		fwtty_dbg(card, "peer(%d:%x) guid: %016llx\n",
drivers/staging/fwserial/fwserial.c:2108:	fwtty_info(&peer->unit, "peer added (guid:%016llx)\n",
drivers/staging/fwserial/fwserial.c:2172:	fwtty_info(&peer->unit, "peer removed (guid:%016llx)\n",
drivers/staging/fwserial/fwserial.c:2259:		fwtty_err(&unit, "no space in port table\n");
drivers/staging/fwserial/fwserial.c:2270:			fwtty_err(&unit, "register tty device error (%d)\n",
drivers/staging/fwserial/fwserial.c:2288:			fwtty_err(&unit, "create loop device failed (%d)\n",
drivers/staging/fwserial/fwserial.c:2309:	fwtty_notice(&unit, "TTY over FireWire on device %s (guid %016llx)\n",
drivers/staging/fwserial/fwserial.c:2316:	fwtty_err(&unit, "unable to add peer unit device (%d)\n", err);
drivers/staging/fwserial/fwserial.c:2557:			fwtty_err(&peer->unit, "no more ports avail\n");
drivers/staging/fwserial/fwserial.c:2599:			fwtty_err(&peer->unit, "PLUG_RSP error (%d)\n", rcode);
drivers/staging/fwserial/fwserial.c:2650:			fwtty_err(&peer->unit, "UNPLUG_RSP error (%d)\n",
drivers/staging/fwserial/fwserial.c:2685:		fwtty_err(&peer->unit, "peer already removed\n");
drivers/staging/fwserial/fwserial.c:2692:	fwtty_dbg(&peer->unit, "mgmt: hdr.code: %04hx\n", pkt->hdr.code);
drivers/staging/fwserial/fwserial.c:2697:			fwtty_err(&peer->unit, "plug req: busy\n");
drivers/staging/fwserial/fwserial.c:2712:			fwtty_notice(&peer->unit, "NACK plug rsp\n");
drivers/staging/fwserial/fwserial.c:2728:			fwtty_err(&peer->unit, "unplug req: busy\n");
drivers/staging/fwserial/fwserial.c:2741:				fwtty_notice(&peer->unit, "NACK unplug?\n");
drivers/staging/fwserial/fwserial.c:2748:		fwtty_err(&peer->unit, "unknown mgmt code %d\n",
drivers/staging/fwserial/fwserial.c:2782:		fwtty_dbg(card, "peer(%d:%x) not found\n", generation, source);
#4 lore raw
In reply to Arushi Singhal
url: https://github.com/0day-ci/linux/commits/Arushi-Singhal/staging-fwserial-replace-a-with-a-to-avoid-precedence-issues/20170215-020955 config: i386-randconfig-s0-02131304 (attached as .config)…

Hi Arushi,

[auto build test ERROR on staging/staging-testing]
[also build test ERROR on v4.10-rc8 next-20170214]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Arushi-Singhal/staging-fwserial-replace-a-with-a-to-avoid-precedence-issues/20170215-020955
config: i386-randconfig-s0-02131304 (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901 reproduce:

        # save the attached .config to linux build tree
        make ARCH=i386 

All error/warnings (new ones prefixed by >>):

>> drivers/staging/fwserial/fwserial.c:101:19: error: "(" may not appear in macro parameter list
    #define to_device((a), b)   (a->b)
                      ^
   In file included from drivers/staging/fwserial/fwserial.c:21:0:
   drivers/staging/fwserial/fwserial.c: In function 'fwtty_log_tx_error':
>> drivers/staging/fwserial/fwserial.c:111:22: error: implicit declaration of function 'to_device' [-Werror=implicit-function-declaration]
     dev_err_ratelimited(to_device(p, device), fmt, ##__VA_ARGS__)
                         ^
   include/linux/device.h:1364:13: note: in definition of macro 'dev_level_ratelimited'
      dev_level(dev, fmt, ##__VA_ARGS__);   \
                ^~~
>> drivers/staging/fwserial/fwserial.c:111:2: note: in expansion of macro 'dev_err_ratelimited'
     dev_err_ratelimited(to_device(p, device), fmt, ##__VA_ARGS__)
     ^~~~~~~~~~~~~~~~~~~
>> drivers/staging/fwserial/fwserial.c:201:3: note: in expansion of macro 'fwtty_err_ratelimited'
      fwtty_err_ratelimited(port, "card busy\n");
      ^~~~~~~~~~~~~~~~~~~~~
>> drivers/staging/fwserial/fwserial.c:111:35: error: 'device' undeclared (first use in this function)
     dev_err_ratelimited(to_device(p, device), fmt, ##__VA_ARGS__)
                                      ^
   include/linux/device.h:1364:13: note: in definition of macro 'dev_level_ratelimited'
      dev_level(dev, fmt, ##__VA_ARGS__);   \
                ^~~
>> drivers/staging/fwserial/fwserial.c:111:2: note: in expansion of macro 'dev_err_ratelimited'
     dev_err_ratelimited(to_device(p, device), fmt, ##__VA_ARGS__)
     ^~~~~~~~~~~~~~~~~~~
>> drivers/staging/fwserial/fwserial.c:201:3: note: in expansion of macro 'fwtty_err_ratelimited'
      fwtty_err_ratelimited(port, "card busy\n");
      ^~~~~~~~~~~~~~~~~~~~~
   drivers/staging/fwserial/fwserial.c:111:35: note: each undeclared identifier is reported only once for each function it appears in
     dev_err_ratelimited(to_device(p, device), fmt, ##__VA_ARGS__)
                                      ^
   include/linux/device.h:1364:13: note: in definition of macro 'dev_level_ratelimited'
      dev_level(dev, fmt, ##__VA_ARGS__);   \
                ^~~
>> drivers/staging/fwserial/fwserial.c:111:2: note: in expansion of macro 'dev_err_ratelimited'
     dev_err_ratelimited(to_device(p, device), fmt, ##__VA_ARGS__)
     ^~~~~~~~~~~~~~~~~~~
>> drivers/staging/fwserial/fwserial.c:201:3: note: in expansion of macro 'fwtty_err_ratelimited'
      fwtty_err_ratelimited(port, "card busy\n");
      ^~~~~~~~~~~~~~~~~~~~~
   In file included from include/linux/printk.h:320:0,
                    from include/linux/kernel.h:13,
                    from include/linux/sched.h:17,
                    from drivers/staging/fwserial/fwserial.c:19:
   drivers/staging/fwserial/fwserial.c: In function '__fwtty_restart_tx':
   drivers/staging/fwserial/fwserial.c:109:23: error: 'device' undeclared (first use in this function)
     dev_dbg(to_device(p, device), "%s: " fmt, __func__, ##__VA_ARGS__)
                          ^
   include/linux/dynamic_debug.h:134:34: note: in definition of macro 'dynamic_dev_dbg'
      __dynamic_dev_dbg(&descriptor, dev, fmt, \
                                     ^~~
>> drivers/staging/fwserial/fwserial.c:109:2: note: in expansion of macro 'dev_dbg'
     dev_dbg(to_device(p, device), "%s: " fmt, __func__, ##__VA_ARGS__)
     ^~~~~~~
>> drivers/staging/fwserial/fwserial.c:290:2: note: in expansion of macro 'fwtty_dbg'
     fwtty_dbg(port, "fifo len: %d avail: %d\n", len, avail);
     ^~~~~~~~~
   drivers/staging/fwserial/fwserial.c: In function 'fwtty_update_port_status':
   drivers/staging/fwserial/fwserial.c:109:23: error: 'device' undeclared (first use in this function)
     dev_dbg(to_device(p, device), "%s: " fmt, __func__, ##__VA_ARGS__)
                          ^
   include/linux/dynamic_debug.h:134:34: note: in definition of macro 'dynamic_dev_dbg'
      __dynamic_dev_dbg(&descriptor, dev, fmt, \
                                     ^~~
>> drivers/staging/fwserial/fwserial.c:109:2: note: in expansion of macro 'dev_dbg'
     dev_dbg(to_device(p, device), "%s: " fmt, __func__, ##__VA_ARGS__)
     ^~~~~~~
   drivers/staging/fwserial/fwserial.c:327:2: note: in expansion of macro 'fwtty_dbg'
     fwtty_dbg(port, "status: %x delta: %x\n", status, delta);
     ^~~~~~~~~
   drivers/staging/fwserial/fwserial.c: In function 'fwtty_emit_breaks':
   drivers/staging/fwserial/fwserial.c:109:23: error: 'device' undeclared (first use in this function)
     dev_dbg(to_device(p, device), "%s: " fmt, __func__, ##__VA_ARGS__)
                          ^
   include/linux/dynamic_debug.h:134:34: note: in definition of macro 'dynamic_dev_dbg'
      __dynamic_dev_dbg(&descriptor, dev, fmt, \
                                     ^~~
>> drivers/staging/fwserial/fwserial.c:109:2: note: in expansion of macro 'dev_dbg'
     dev_dbg(to_device(p, device), "%s: " fmt, __func__, ##__VA_ARGS__)
     ^~~~~~~
   drivers/staging/fwserial/fwserial.c:523:2: note: in expansion of macro 'fwtty_dbg'
     fwtty_dbg(port, "sending %d brks\n", n);
     ^~~~~~~~~
   drivers/staging/fwserial/fwserial.c: In function 'fwtty_rx':
   drivers/staging/fwserial/fwserial.c:109:23: error: 'device' undeclared (first use in this function)
     dev_dbg(to_device(p, device), "%s: " fmt, __func__, ##__VA_ARGS__)
                          ^
   include/linux/dynamic_debug.h:134:34: note: in definition of macro 'dynamic_dev_dbg'
      __dynamic_dev_dbg(&descriptor, dev, fmt, \
                                     ^~~
>> drivers/staging/fwserial/fwserial.c:109:2: note: in expansion of macro 'dev_dbg'
     dev_dbg(to_device(p, device), "%s: " fmt, __func__, ##__VA_ARGS__)
     ^~~~~~~
   drivers/staging/fwserial/fwserial.c:547:2: note: in expansion of macro 'fwtty_dbg'
     fwtty_dbg(port, "%d\n", n);
     ^~~~~~~~~
   In file included from drivers/staging/fwserial/fwserial.c:21:0:
   drivers/staging/fwserial/fwserial.c: In function 'fwtty_port_handler':
>> drivers/staging/fwserial/fwserial.c:111:35: error: 'device' undeclared (first use in this function)
     dev_err_ratelimited(to_device(p, device), fmt, ##__VA_ARGS__)
                                      ^
   include/linux/device.h:1364:13: note: in definition of macro 'dev_level_ratelimited'
      dev_level(dev, fmt, ##__VA_ARGS__);   \
                ^~~
>> drivers/staging/fwserial/fwserial.c:111:2: note: in expansion of macro 'dev_err_ratelimited'
     dev_err_ratelimited(to_device(p, device), fmt, ##__VA_ARGS__)
     ^~~~~~~~~~~~~~~~~~~
   drivers/staging/fwserial/fwserial.c:630:3: note: in expansion of macro 'fwtty_err_ratelimited'
      fwtty_err_ratelimited(port, "ignoring unauthenticated data\n");
      ^~~~~~~~~~~~~~~~~~~~~
   In file included from include/linux/printk.h:320:0,
                    from include/linux/kernel.h:13,
                    from include/linux/sched.h:17,
                    from drivers/staging/fwserial/fwserial.c:19:
   drivers/staging/fwserial/fwserial.c: In function 'fwtty_tx_complete':
   drivers/staging/fwserial/fwserial.c:109:23: error: 'device' undeclared (first use in this function)
     dev_dbg(to_device(p, device), "%s: " fmt, __func__, ##__VA_ARGS__)
                          ^
   include/linux/dynamic_debug.h:134:34: note: in definition of macro 'dynamic_dev_dbg'
      __dynamic_dev_dbg(&descriptor, dev, fmt, \
                                     ^~~
>> drivers/staging/fwserial/fwserial.c:109:2: note: in expansion of macro 'dev_dbg'
     dev_dbg(to_device(p, device), "%s: " fmt, __func__, ##__VA_ARGS__)
     ^~~~~~~
   drivers/staging/fwserial/fwserial.c:687:2: note: in expansion of macro 'fwtty_dbg'
     fwtty_dbg(port, "rcode: %d\n", rcode);
     ^~~~~~~~~
   drivers/staging/fwserial/fwserial.c: In function 'fwtty_tx':
   drivers/staging/fwserial/fwserial.c:109:23: error: 'device' undeclared (first use in this function)
     dev_dbg(to_device(p, device), "%s: " fmt, __func__, ##__VA_ARGS__)
                          ^
   include/linux/dynamic_debug.h:134:34: note: in definition of macro 'dynamic_dev_dbg'
      __dynamic_dev_dbg(&descriptor, dev, fmt, \
                                     ^~~
>> drivers/staging/fwserial/fwserial.c:109:2: note: in expansion of macro 'dev_dbg'
     dev_dbg(to_device(p, device), "%s: " fmt, __func__, ##__VA_ARGS__)
     ^~~~~~~
   drivers/staging/fwserial/fwserial.c:750:3: note: in expansion of macro 'fwtty_dbg'
      fwtty_dbg(port, "out: %u rem: %d\n", txn->dma_pended.len, n);
      ^~~~~~~~~
   drivers/staging/fwserial/fwserial.c: In function 'fwtty_write_xchar':
   drivers/staging/fwserial/fwserial.c:109:23: error: 'device' undeclared (first use in this function)
     dev_dbg(to_device(p, device), "%s: " fmt, __func__, ##__VA_ARGS__)
                          ^
   include/linux/dynamic_debug.h:134:34: note: in definition of macro 'dynamic_dev_dbg'
      __dynamic_dev_dbg(&descriptor, dev, fmt, \
                                     ^~~
>> drivers/staging/fwserial/fwserial.c:109:2: note: in expansion of macro 'dev_dbg'
     dev_dbg(to_device(p, device), "%s: " fmt, __func__, ##__VA_ARGS__)
     ^~~~~~~
   drivers/staging/fwserial/fwserial.c:820:2: note: in expansion of macro 'fwtty_dbg'
     fwtty_dbg(port, "%02x\n", ch);
     ^~~~~~~~~
   drivers/staging/fwserial/fwserial.c: In function 'fwtty_port_dtr_rts':
   drivers/staging/fwserial/fwserial.c:109:23: error: 'device' undeclared (first use in this function)
     dev_dbg(to_device(p, device), "%s: " fmt, __func__, ##__VA_ARGS__)
                          ^
   include/linux/dynamic_debug.h:134:34: note: in definition of macro 'dynamic_dev_dbg'
      __dynamic_dev_dbg(&descriptor, dev, fmt, \
                                     ^~~
>> drivers/staging/fwserial/fwserial.c:109:2: note: in expansion of macro 'dev_dbg'
     dev_dbg(to_device(p, device), "%s: " fmt, __func__, ##__VA_ARGS__)
     ^~~~~~~
   drivers/staging/fwserial/fwserial.c:905:2: note: in expansion of macro 'fwtty_dbg'
     fwtty_dbg(port, "on/off: %d\n", on);
     ^~~~~~~~~
   drivers/staging/fwserial/fwserial.c: In function 'fwtty_port_carrier_raised':
   drivers/staging/fwserial/fwserial.c:109:23: error: 'device' undeclared (first use in this function)
     dev_dbg(to_device(p, device), "%s: " fmt, __func__, ##__VA_ARGS__)
                          ^
   include/linux/dynamic_debug.h:134:34: note: in definition of macro 'dynamic_dev_dbg'
      __dynamic_dev_dbg(&descriptor, dev, fmt, \
                                     ^~~

vim +101 drivers/staging/fwserial/fwserial.c

13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */
16
17 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
18

  > 19	#include <linux/sched.h>
    20	#include <linux/slab.h>
  > 21	#include <linux/device.h>
    22	#include <linux/mod_devicetable.h>
    23	#include <linux/rculist.h>
    24	#include <linux/workqueue.h>
    25	#include <linux/ratelimit.h>
    26	#include <linux/bug.h>
    27	#include <linux/uaccess.h>
    28	
    29	#include "fwserial.h"
    30	
    31	#define be32_to_u64(hi, lo)  ((u64)be32_to_cpu(hi) << 32 | be32_to_cpu(lo))
    32	
    33	#define LINUX_VENDOR_ID   0xd00d1eU  /* same id used in card root directory   */
    34	#define FWSERIAL_VERSION  0x00e81cU  /* must be unique within LINUX_VENDOR_ID */
    35	
    36	/* configurable options */
    37	static int num_ttys = 4;	    /* # of std ttys to create per fw_card    */
    38					    /* - doubles as loopback port index       */
    39	static bool auto_connect = true;    /* try to VIRT_CABLE to every peer        */
    40	static bool create_loop_dev = true; /* create a loopback device for each card */
    41	
    42	module_param_named(ttys, num_ttys, int, 0644);
    43	module_param_named(auto, auto_connect, bool, 0644);
    44	module_param_named(loop, create_loop_dev, bool, 0644);
    45	
    46	/*
    47	 * Threshold below which the tty is woken for writing
    48	 * - should be equal to WAKEUP_CHARS in drivers/tty/n_tty.c because
    49	 *   even if the writer is woken, n_tty_poll() won't set POLLOUT until
    50	 *   our fifo is below this level
    51	 */
    52	#define WAKEUP_CHARS             256
    53	
    54	/**
    55	 * fwserial_list: list of every fw_serial created for each fw_card
    56	 * See discussion in fwserial_probe.
    57	 */
    58	static LIST_HEAD(fwserial_list);
    59	static DEFINE_MUTEX(fwserial_list_mutex);
    60	
    61	/**
    62	 * port_table: array of tty ports allocated to each fw_card
    63	 *
    64	 * tty ports are allocated during probe when an fw_serial is first
    65	 * created for a given fw_card. Ports are allocated in a contiguous block,
    66	 * each block consisting of 'num_ports' ports.
    67	 */
    68	static struct fwtty_port *port_table[MAX_TOTAL_PORTS];
    69	static DEFINE_MUTEX(port_table_lock);
    70	static bool port_table_corrupt;
    71	#define FWTTY_INVALID_INDEX  MAX_TOTAL_PORTS
    72	
    73	#define loop_idx(port)	(((port)->index) / num_ports)
    74	#define table_idx(loop)	((loop) * num_ports + num_ttys)
    75	
    76	/* total # of tty ports created per fw_card */
    77	static int num_ports;
    78	
    79	/* slab used as pool for struct fwtty_transactions */
    80	static struct kmem_cache *fwtty_txn_cache;
    81	
    82	struct tty_driver *fwtty_driver;
    83	static struct tty_driver *fwloop_driver;
    84	
    85	static struct dentry *fwserial_debugfs;
    86	
    87	struct fwtty_transaction;
    88	typedef void (*fwtty_transaction_cb)(struct fw_card *card, int rcode,
    89					     void *data, size_t length,
    90					     struct fwtty_transaction *txn);
    91	
    92	struct fwtty_transaction {
    93		struct fw_transaction      fw_txn;
    94		fwtty_transaction_cb       callback;
    95		struct fwtty_port	   *port;
    96		union {
    97			struct dma_pending dma_pended;
    98		};
    99	};
   100	
 > 101	#define to_device((a), b)			(a->b)
   102	#define fwtty_err(p, fmt, ...)						\
   103		dev_err(to_device(p, device), fmt, ##__VA_ARGS__)
   104	#define fwtty_info(p, fmt, ...)						\
   105		dev_info(to_device(p, device), fmt, ##__VA_ARGS__)
   106	#define fwtty_notice(p, fmt, ...)					\
   107		dev_notice(to_device(p, device), fmt, ##__VA_ARGS__)
   108	#define fwtty_dbg(p, fmt, ...)						\
 > 109		dev_dbg(to_device(p, device), "%s: " fmt, __func__, ##__VA_ARGS__)
   110	#define fwtty_err_ratelimited(p, fmt, ...)				\
 > 111		dev_err_ratelimited(to_device(p, device), fmt, ##__VA_ARGS__)
   112	
   113	#ifdef DEBUG
   114	static inline void debug_short_write(struct fwtty_port *port, int c, int n)
   115	{
   116		int avail;
   117	
   118		if (n < c) {
   119			spin_lock_bh(&port->lock);
   120			avail = dma_fifo_avail(&port->tx_fifo);
   121			spin_unlock_bh(&port->lock);
   122			fwtty_dbg(port, "short write: avail:%d req:%d wrote:%d\n",
   123				  avail, c, n);
   124		}
   125	}
   126	#else
   127	#define debug_short_write(port, c, n)
   128	#endif
   129	
   130	static struct fwtty_peer *__fwserial_peer_by_node_id(struct fw_card *card,
   131							     int generation, int id);
   132	
   133	#ifdef FWTTY_PROFILING
   134	
   135	static void fwtty_profile_fifo(struct fwtty_port *port, unsigned int *stat)
   136	{
   137		spin_lock_bh(&port->lock);
   138		fwtty_profile_data(stat, dma_fifo_avail(&port->tx_fifo));
   139		spin_unlock_bh(&port->lock);
   140	}
   141	
   142	static void fwtty_dump_profile(struct seq_file *m, struct stats *stats)
   143	{
   144		/* for each stat, print sum of 0 to 2^k, then individually */
   145		int k = 4;
   146		unsigned int sum;
   147		int j;
   148		char t[10];
   149	
   150		snprintf(t, 10, "< %d", 1 << k);
   151		seq_printf(m, "\n%14s  %6s", " ", t);
   152		for (j = k + 1; j < DISTRIBUTION_MAX_INDEX; ++j)
   153			seq_printf(m, "%6d", 1 << j);
   154	
   155		++k;
   156		for (j = 0, sum = 0; j <= k; ++j)
   157			sum += stats->reads[j];
   158		seq_printf(m, "\n%14s: %6d", "reads", sum);
   159		for (j = k + 1; j <= DISTRIBUTION_MAX_INDEX; ++j)
   160			seq_printf(m, "%6d", stats->reads[j]);
   161	
   162		for (j = 0, sum = 0; j <= k; ++j)
   163			sum += stats->writes[j];
   164		seq_printf(m, "\n%14s: %6d", "writes", sum);
   165		for (j = k + 1; j <= DISTRIBUTION_MAX_INDEX; ++j)
   166			seq_printf(m, "%6d", stats->writes[j]);
   167	
   168		for (j = 0, sum = 0; j <= k; ++j)
   169			sum += stats->txns[j];
   170		seq_printf(m, "\n%14s: %6d", "txns", sum);
   171		for (j = k + 1; j <= DISTRIBUTION_MAX_INDEX; ++j)
   172			seq_printf(m, "%6d", stats->txns[j]);
   173	
   174		for (j = 0, sum = 0; j <= k; ++j)
   175			sum += stats->unthrottle[j];
   176		seq_printf(m, "\n%14s: %6d", "avail @ unthr", sum);
   177		for (j = k + 1; j <= DISTRIBUTION_MAX_INDEX; ++j)
   178			seq_printf(m, "%6d", stats->unthrottle[j]);
   179	}
   180	
   181	#else
   182	#define fwtty_profile_fifo(port, stat)
   183	#define fwtty_dump_profile(m, stats)
   184	#endif
   185	
   186	/*
   187	 * Returns the max receive packet size for the given node
   188	 * Devices which are OHCI v1.0/ v1.1/ v1.2-draft or RFC 2734 compliant
   189	 * are required by specification to support max_rec of 8 (512 bytes) or more.
   190	 */
   191	static inline int device_max_receive(struct fw_device *fw_device)
   192	{
   193		/* see IEEE 1394-2008 table 8-8 */
   194		return min(2 << fw_device->max_rec, 4096);
   195	}
   196	
   197	static void fwtty_log_tx_error(struct fwtty_port *port, int rcode)
   198	{
   199		switch (rcode) {
   200		case RCODE_SEND_ERROR:
 > 201			fwtty_err_ratelimited(port, "card busy\n");
   202			break;
   203		case RCODE_ADDRESS_ERROR:
   204			fwtty_err_ratelimited(port, "bad unit addr or write length\n");
   205			break;
   206		case RCODE_DATA_ERROR:
   207			fwtty_err_ratelimited(port, "failed rx\n");
   208			break;
   209		case RCODE_NO_ACK:
   210			fwtty_err_ratelimited(port, "missing ack\n");
   211			break;
   212		case RCODE_BUSY:
   213			fwtty_err_ratelimited(port, "remote busy\n");
   214			break;
   215		default:
   216			fwtty_err_ratelimited(port, "failed tx: %d\n", rcode);
   217		}
   218	}
   219	
   220	static void fwtty_txn_constructor(void *this)
   221	{
   222		struct fwtty_transaction *txn = this;
   223	
   224		init_timer(&txn->fw_txn.split_timeout_timer);
   225	}
   226	
   227	static void fwtty_common_callback(struct fw_card *card, int rcode,
   228					  void *payload, size_t len, void *cb_data)
   229	{
   230		struct fwtty_transaction *txn = cb_data;
   231		struct fwtty_port *port = txn->port;
   232	
   233		if (port && rcode != RCODE_COMPLETE)
   234			fwtty_log_tx_error(port, rcode);
   235		if (txn->callback)
   236			txn->callback(card, rcode, payload, len, txn);
   237		kmem_cache_free(fwtty_txn_cache, txn);
   238	}
   239	
   240	static int fwtty_send_data_async(struct fwtty_peer *peer, int tcode,
   241					 unsigned long long addr, void *payload,
   242					 size_t len, fwtty_transaction_cb callback,
   243					 struct fwtty_port *port)
   244	{
   245		struct fwtty_transaction *txn;
   246		int generation;
   247	
   248		txn = kmem_cache_alloc(fwtty_txn_cache, GFP_ATOMIC);
   249		if (!txn)
   250			return -ENOMEM;
   251	
   252		txn->callback = callback;
   253		txn->port = port;
   254	
   255		generation = peer->generation;
   256		smp_rmb();
   257		fw_send_request(peer->serial->card, &txn->fw_txn, tcode,
   258				peer->node_id, generation, peer->speed, addr, payload,
   259				len, fwtty_common_callback, txn);
   260		return 0;
   261	}
   262	
   263	static void fwtty_send_txn_async(struct fwtty_peer *peer,
   264					 struct fwtty_transaction *txn, int tcode,
   265					 unsigned long long addr, void *payload,
   266					 size_t len, fwtty_transaction_cb callback,
   267					 struct fwtty_port *port)
   268	{
   269		int generation;
   270	
   271		txn->callback = callback;
   272		txn->port = port;
   273	
   274		generation = peer->generation;
   275		smp_rmb();
   276		fw_send_request(peer->serial->card, &txn->fw_txn, tcode,
   277				peer->node_id, generation, peer->speed, addr, payload,
   278				len, fwtty_common_callback, txn);
   279	}
   280	
   281	static void __fwtty_restart_tx(struct fwtty_port *port)
   282	{
   283		int len, avail;
   284	
   285		len = dma_fifo_out_level(&port->tx_fifo);
   286		if (len)
   287			schedule_delayed_work(&port->drain, 0);
   288		avail = dma_fifo_avail(&port->tx_fifo);
   289	
 > 290		fwtty_dbg(port, "fifo len: %d avail: %d\n", len, avail);

291 }
292
293 static void fwtty_restart_tx(struct fwtty_port *port)

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#5 lore raw
In reply to Arushi Singhal
url: https://github.com/0day-ci/linux/commits/Arushi-Singhal/staging-fwserial-replace-a-with-a-to-avoid-precedence-issues/20170215-020955 config: m68k-allyesconfig (attached as .config) compiler…

Hi Arushi,

[auto build test ERROR on staging/staging-testing]
[also build test ERROR on v4.10-rc8 next-20170214]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Arushi-Singhal/staging-fwserial-replace-a-with-a-to-avoid-precedence-issues/20170215-020955
config: m68k-allyesconfig (attached as .config)
compiler: m68k-linux-gcc (GCC) 4.9.0
reproduce:
wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=m68k

All error/warnings (new ones prefixed by >>):

drivers/staging/fwserial/fwserial.c:101:19: error: "(" may not appear in macro parameter list

    #define to_device((a), b)   (a->b)
                      ^
   In file included from include/linux/device.h:27:0,
                    from drivers/staging/fwserial/fwserial.c:21:
   drivers/staging/fwserial/fwserial.c: In function 'fwtty_log_tx_error':
>> include/linux/ratelimit.h:36:9: error: implicit declaration of function 'to_device' [-Werror=implicit-function-declaration]
     struct ratelimit_state name =     \
            ^
>> include/linux/device.h:1360:9: note: in expansion of macro 'DEFINE_RATELIMIT_STATE'
     static DEFINE_RATELIMIT_STATE(_rs,    \
            ^
>> include/linux/device.h:1374:2: note: in expansion of macro 'dev_level_ratelimited'
     dev_level_ratelimited(dev_err, dev, fmt, ##__VA_ARGS__)
     ^
   drivers/staging/fwserial/fwserial.c:111:2: note: in expansion of macro 'dev_err_ratelimited'
     dev_err_ratelimited(to_device(p, device), fmt, ##__VA_ARGS__)
     ^
   drivers/staging/fwserial/fwserial.c:201:3: note: in expansion of macro 'fwtty_err_ratelimited'
      fwtty_err_ratelimited(port, "card busy\n");
      ^
   In file included from drivers/staging/fwserial/fwserial.c:21:0:
   drivers/staging/fwserial/fwserial.c:111:35: error: 'device' undeclared (first use in this function)
     dev_err_ratelimited(to_device(p, device), fmt, ##__VA_ARGS__)
                                      ^
   include/linux/device.h:1364:13: note: in definition of macro 'dev_level_ratelimited'
      dev_level(dev, fmt, ##__VA_ARGS__);   \
                ^
   drivers/staging/fwserial/fwserial.c:111:2: note: in expansion of macro 'dev_err_ratelimited'
     dev_err_ratelimited(to_device(p, device), fmt, ##__VA_ARGS__)
     ^
   drivers/staging/fwserial/fwserial.c:201:3: note: in expansion of macro 'fwtty_err_ratelimited'
      fwtty_err_ratelimited(port, "card busy\n");
      ^
   drivers/staging/fwserial/fwserial.c:111:35: note: each undeclared identifier is reported only once for each function it appears in
     dev_err_ratelimited(to_device(p, device), fmt, ##__VA_ARGS__)
                                      ^
   include/linux/device.h:1364:13: note: in definition of macro 'dev_level_ratelimited'
      dev_level(dev, fmt, ##__VA_ARGS__);   \
                ^
   drivers/staging/fwserial/fwserial.c:111:2: note: in expansion of macro 'dev_err_ratelimited'
     dev_err_ratelimited(to_device(p, device), fmt, ##__VA_ARGS__)
     ^
   drivers/staging/fwserial/fwserial.c:201:3: note: in expansion of macro 'fwtty_err_ratelimited'
      fwtty_err_ratelimited(port, "card busy\n");
      ^
   In file included from include/linux/printk.h:320:0,
                    from include/linux/kernel.h:13,
                    from include/linux/sched.h:17,
                    from drivers/staging/fwserial/fwserial.c:19:
   drivers/staging/fwserial/fwserial.c: In function '__fwtty_restart_tx':
   drivers/staging/fwserial/fwserial.c:109:23: error: 'device' undeclared (first use in this function)
     dev_dbg(to_device(p, device), "%s: " fmt, __func__, ##__VA_ARGS__)
                          ^
   include/linux/dynamic_debug.h:134:34: note: in definition of macro 'dynamic_dev_dbg'
      __dynamic_dev_dbg(&descriptor, dev, fmt, \
                                     ^
   drivers/staging/fwserial/fwserial.c:109:2: note: in expansion of macro 'dev_dbg'
     dev_dbg(to_device(p, device), "%s: " fmt, __func__, ##__VA_ARGS__)
     ^
   drivers/staging/fwserial/fwserial.c:290:2: note: in expansion of macro 'fwtty_dbg'
     fwtty_dbg(port, "fifo len: %d avail: %d\n", len, avail);
     ^
   drivers/staging/fwserial/fwserial.c: In function 'fwtty_update_port_status':
   drivers/staging/fwserial/fwserial.c:109:23: error: 'device' undeclared (first use in this function)
     dev_dbg(to_device(p, device), "%s: " fmt, __func__, ##__VA_ARGS__)
                          ^
   include/linux/dynamic_debug.h:134:34: note: in definition of macro 'dynamic_dev_dbg'
      __dynamic_dev_dbg(&descriptor, dev, fmt, \
                                     ^
   drivers/staging/fwserial/fwserial.c:109:2: note: in expansion of macro 'dev_dbg'
     dev_dbg(to_device(p, device), "%s: " fmt, __func__, ##__VA_ARGS__)
     ^
   drivers/staging/fwserial/fwserial.c:327:2: note: in expansion of macro 'fwtty_dbg'
     fwtty_dbg(port, "status: %x delta: %x\n", status, delta);
     ^
   drivers/staging/fwserial/fwserial.c: In function 'fwtty_emit_breaks':
   drivers/staging/fwserial/fwserial.c:109:23: error: 'device' undeclared (first use in this function)
     dev_dbg(to_device(p, device), "%s: " fmt, __func__, ##__VA_ARGS__)
                          ^
   include/linux/dynamic_debug.h:134:34: note: in definition of macro 'dynamic_dev_dbg'
      __dynamic_dev_dbg(&descriptor, dev, fmt, \
                                     ^
   drivers/staging/fwserial/fwserial.c:109:2: note: in expansion of macro 'dev_dbg'
     dev_dbg(to_device(p, device), "%s: " fmt, __func__, ##__VA_ARGS__)
     ^
   drivers/staging/fwserial/fwserial.c:523:2: note: in expansion of macro 'fwtty_dbg'
     fwtty_dbg(port, "sending %d brks\n", n);
     ^
   drivers/staging/fwserial/fwserial.c: In function 'fwtty_rx':
   drivers/staging/fwserial/fwserial.c:109:23: error: 'device' undeclared (first use in this function)
     dev_dbg(to_device(p, device), "%s: " fmt, __func__, ##__VA_ARGS__)
                          ^
   include/linux/dynamic_debug.h:134:34: note: in definition of macro 'dynamic_dev_dbg'
      __dynamic_dev_dbg(&descriptor, dev, fmt, \
                                     ^
   drivers/staging/fwserial/fwserial.c:109:2: note: in expansion of macro 'dev_dbg'
     dev_dbg(to_device(p, device), "%s: " fmt, __func__, ##__VA_ARGS__)
     ^
   drivers/staging/fwserial/fwserial.c:547:2: note: in expansion of macro 'fwtty_dbg'
     fwtty_dbg(port, "%d\n", n);
     ^
   In file included from drivers/staging/fwserial/fwserial.c:21:0:
   drivers/staging/fwserial/fwserial.c: In function 'fwtty_port_handler':
   drivers/staging/fwserial/fwserial.c:111:35: error: 'device' undeclared (first use in this function)
     dev_err_ratelimited(to_device(p, device), fmt, ##__VA_ARGS__)
                                      ^
   include/linux/device.h:1364:13: note: in definition of macro 'dev_level_ratelimited'
      dev_level(dev, fmt, ##__VA_ARGS__);   \
                ^
   drivers/staging/fwserial/fwserial.c:111:2: note: in expansion of macro 'dev_err_ratelimited'
     dev_err_ratelimited(to_device(p, device), fmt, ##__VA_ARGS__)
     ^

vim +/to_device +36 include/linux/ratelimit.h

717115e1 Dave Young      2008-07-25  30  
89e3f909 Dmitry Monakhov 2014-12-12  31  #define RATELIMIT_STATE_INIT_DISABLED					\
89e3f909 Dmitry Monakhov 2014-12-12  32  	RATELIMIT_STATE_INIT(ratelimit_state, 0, DEFAULT_RATELIMIT_BURST)
89e3f909 Dmitry Monakhov 2014-12-12  33  
89e3f909 Dmitry Monakhov 2014-12-12  34  #define DEFINE_RATELIMIT_STATE(name, interval_init, burst_init)		\
89e3f909 Dmitry Monakhov 2014-12-12  35  									\
89e3f909 Dmitry Monakhov 2014-12-12 @36  	struct ratelimit_state name =					\
89e3f909 Dmitry Monakhov 2014-12-12  37  		RATELIMIT_STATE_INIT(name, interval_init, burst_init)	\
89e3f909 Dmitry Monakhov 2014-12-12  38  
f40c396a OGAWA Hirofumi  2010-05-24  39  static inline void ratelimit_state_init(struct ratelimit_state *rs,

:::::: The code at line 36 was first introduced by commit
:::::: 89e3f90995b370fa46922eece62ea23f039a202d ratelimit: add initialization macro

:::::: TO: Dmitry Monakhov <[email protected]> :::::: CC: Linus Torvalds <[email protected]>

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation