Commit 6b8a66ee919e40111e3d257b2c22b5773e34ead1

Authored by Joe Perches
Committed by David S. Miller
1 parent 8d77c036b5

tun: Convert logging messages to pr_<level> and tun_debug

Use the current logging forms with pr_fmt.
Convert DBG macro to tun_debug, use netdev_printk as well.
Add printf verification when TUN_DEBUG not defined.
Miscellaneous comment typo fix.

Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

Showing 1 changed file with 51 additions and 32 deletions Side-by-side Diff

... ... @@ -34,6 +34,8 @@
34 34 * Modifications for 2.3.99-pre5 kernel.
35 35 */
36 36  
  37 +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  38 +
37 39 #define DRV_NAME "tun"
38 40 #define DRV_VERSION "1.6"
39 41 #define DRV_DESCRIPTION "Universal TUN/TAP device driver"
40 42  
... ... @@ -76,11 +78,27 @@
76 78 #ifdef TUN_DEBUG
77 79 static int debug;
78 80  
79   -#define DBG if(tun->debug)printk
80   -#define DBG1 if(debug==2)printk
  81 +#define tun_debug(level, tun, fmt, args...) \
  82 +do { \
  83 + if (tun->debug) \
  84 + netdev_printk(level, tun->dev, fmt, ##args); \
  85 +} while (0)
  86 +#define DBG1(level, fmt, args...) \
  87 +do { \
  88 + if (debug == 2) \
  89 + printk(level fmt, ##args); \
  90 +} while (0)
81 91 #else
82   -#define DBG( a... )
83   -#define DBG1( a... )
  92 +#define tun_debug(level, tun, fmt, args...) \
  93 +do { \
  94 + if (0) \
  95 + netdev_printk(level, tun->dev, fmt, ##args); \
  96 +} while (0)
  97 +#define DBG1(level, fmt, args...) \
  98 +do { \
  99 + if (0) \
  100 + printk(level fmt, ##args); \
  101 +} while (0)
84 102 #endif
85 103  
86 104 #define FLT_EXACT_COUNT 8
... ... @@ -205,7 +223,7 @@
205 223 tun_detach(tfile->tun);
206 224 }
207 225  
208   -/* TAP filterting */
  226 +/* TAP filtering */
209 227 static void addr_hash_set(u32 *mask, const u8 *addr)
210 228 {
211 229 int n = ether_crc(ETH_ALEN, addr) >> 26;
... ... @@ -360,7 +378,7 @@
360 378 {
361 379 struct tun_struct *tun = netdev_priv(dev);
362 380  
363   - DBG(KERN_INFO "%s: tun_net_xmit %d\n", tun->dev->name, skb->len);
  381 + tun_debug(KERN_INFO, tun, "tun_net_xmit %d\n", skb->len);
364 382  
365 383 /* Drop packet if interface is not attached */
366 384 if (!tun->tfile)
... ... @@ -499,7 +517,7 @@
499 517  
500 518 sk = tun->socket.sk;
501 519  
502   - DBG(KERN_INFO "%s: tun_chr_poll\n", tun->dev->name);
  520 + tun_debug(KERN_INFO, tun, "tun_chr_poll\n");
503 521  
504 522 poll_wait(file, &tun->wq.wait, wait);
505 523  
... ... @@ -690,7 +708,7 @@
690 708 if (!tun)
691 709 return -EBADFD;
692 710  
693   - DBG(KERN_INFO "%s: tun_chr_write %ld\n", tun->dev->name, count);
  711 + tun_debug(KERN_INFO, tun, "tun_chr_write %ld\n", count);
694 712  
695 713 result = tun_get_user(tun, iv, iov_length(iv, count),
696 714 file->f_flags & O_NONBLOCK);
... ... @@ -739,7 +757,7 @@
739 757 else if (sinfo->gso_type & SKB_GSO_UDP)
740 758 gso.gso_type = VIRTIO_NET_HDR_GSO_UDP;
741 759 else {
742   - printk(KERN_ERR "tun: unexpected GSO type: "
  760 + pr_err("unexpected GSO type: "
743 761 "0x%x, gso_size %d, hdr_len %d\n",
744 762 sinfo->gso_type, gso.gso_size,
745 763 gso.hdr_len);
... ... @@ -786,7 +804,7 @@
786 804 struct sk_buff *skb;
787 805 ssize_t ret = 0;
788 806  
789   - DBG(KERN_INFO "%s: tun_chr_read\n", tun->dev->name);
  807 + tun_debug(KERN_INFO, tun, "tun_chr_read\n");
790 808  
791 809 add_wait_queue(&tun->wq.wait, &wait);
792 810 while (len) {
... ... @@ -1083,7 +1101,7 @@
1083 1101 if (device_create_file(&tun->dev->dev, &dev_attr_tun_flags) ||
1084 1102 device_create_file(&tun->dev->dev, &dev_attr_owner) ||
1085 1103 device_create_file(&tun->dev->dev, &dev_attr_group))
1086   - printk(KERN_ERR "Failed to create tun sysfs files\n");
  1104 + pr_err("Failed to create tun sysfs files\n");
1087 1105  
1088 1106 sk->sk_destruct = tun_sock_destruct;
1089 1107  
... ... @@ -1092,7 +1110,7 @@
1092 1110 goto failed;
1093 1111 }
1094 1112  
1095   - DBG(KERN_INFO "%s: tun_set_iff\n", tun->dev->name);
  1113 + tun_debug(KERN_INFO, tun, "tun_set_iff\n");
1096 1114  
1097 1115 if (ifr->ifr_flags & IFF_NO_PI)
1098 1116 tun->flags |= TUN_NO_PI;
... ... @@ -1129,7 +1147,7 @@
1129 1147 static int tun_get_iff(struct net *net, struct tun_struct *tun,
1130 1148 struct ifreq *ifr)
1131 1149 {
1132   - DBG(KERN_INFO "%s: tun_get_iff\n", tun->dev->name);
  1150 + tun_debug(KERN_INFO, tun, "tun_get_iff\n");
1133 1151  
1134 1152 strcpy(ifr->ifr_name, tun->dev->name);
1135 1153  
... ... @@ -1229,7 +1247,7 @@
1229 1247 if (!tun)
1230 1248 goto unlock;
1231 1249  
1232   - DBG(KERN_INFO "%s: tun_chr_ioctl cmd %d\n", tun->dev->name, cmd);
  1250 + tun_debug(KERN_INFO, tun, "tun_chr_ioctl cmd %d\n", cmd);
1233 1251  
1234 1252 ret = 0;
1235 1253 switch (cmd) {
... ... @@ -1249,8 +1267,8 @@
1249 1267 else
1250 1268 tun->flags &= ~TUN_NOCHECKSUM;
1251 1269  
1252   - DBG(KERN_INFO "%s: checksum %s\n",
1253   - tun->dev->name, arg ? "disabled" : "enabled");
  1270 + tun_debug(KERN_INFO, tun, "checksum %s\n",
  1271 + arg ? "disabled" : "enabled");
1254 1272 break;
1255 1273  
1256 1274 case TUNSETPERSIST:
1257 1275  
1258 1276  
1259 1277  
1260 1278  
... ... @@ -1260,33 +1278,34 @@
1260 1278 else
1261 1279 tun->flags &= ~TUN_PERSIST;
1262 1280  
1263   - DBG(KERN_INFO "%s: persist %s\n",
1264   - tun->dev->name, arg ? "enabled" : "disabled");
  1281 + tun_debug(KERN_INFO, tun, "persist %s\n",
  1282 + arg ? "enabled" : "disabled");
1265 1283 break;
1266 1284  
1267 1285 case TUNSETOWNER:
1268 1286 /* Set owner of the device */
1269 1287 tun->owner = (uid_t) arg;
1270 1288  
1271   - DBG(KERN_INFO "%s: owner set to %d\n", tun->dev->name, tun->owner);
  1289 + tun_debug(KERN_INFO, tun, "owner set to %d\n", tun->owner);
1272 1290 break;
1273 1291  
1274 1292 case TUNSETGROUP:
1275 1293 /* Set group of the device */
1276 1294 tun->group= (gid_t) arg;
1277 1295  
1278   - DBG(KERN_INFO "%s: group set to %d\n", tun->dev->name, tun->group);
  1296 + tun_debug(KERN_INFO, tun, "group set to %d\n", tun->group);
1279 1297 break;
1280 1298  
1281 1299 case TUNSETLINK:
1282 1300 /* Only allow setting the type when the interface is down */
1283 1301 if (tun->dev->flags & IFF_UP) {
1284   - DBG(KERN_INFO "%s: Linktype set failed because interface is up\n",
1285   - tun->dev->name);
  1302 + tun_debug(KERN_INFO, tun,
  1303 + "Linktype set failed because interface is up\n");
1286 1304 ret = -EBUSY;
1287 1305 } else {
1288 1306 tun->dev->type = (int) arg;
1289   - DBG(KERN_INFO "%s: linktype set to %d\n", tun->dev->name, tun->dev->type);
  1307 + tun_debug(KERN_INFO, tun, "linktype set to %d\n",
  1308 + tun->dev->type);
1290 1309 ret = 0;
1291 1310 }
1292 1311 break;
... ... @@ -1318,8 +1337,8 @@
1318 1337  
1319 1338 case SIOCSIFHWADDR:
1320 1339 /* Set hw address */
1321   - DBG(KERN_DEBUG "%s: set hw address: %pM\n",
1322   - tun->dev->name, ifr.ifr_hwaddr.sa_data);
  1340 + tun_debug(KERN_DEBUG, tun, "set hw address: %pM\n",
  1341 + ifr.ifr_hwaddr.sa_data);
1323 1342  
1324 1343 ret = dev_set_mac_address(tun->dev, &ifr.ifr_hwaddr);
1325 1344 break;
... ... @@ -1433,7 +1452,7 @@
1433 1452 if (!tun)
1434 1453 return -EBADFD;
1435 1454  
1436   - DBG(KERN_INFO "%s: tun_chr_fasync %d\n", tun->dev->name, on);
  1455 + tun_debug(KERN_INFO, tun, "tun_chr_fasync %d\n", on);
1437 1456  
1438 1457 if ((ret = fasync_helper(fd, file, on, &tun->fasync)) < 0)
1439 1458 goto out;
... ... @@ -1455,7 +1474,7 @@
1455 1474 {
1456 1475 struct tun_file *tfile;
1457 1476  
1458   - DBG1(KERN_INFO "tunX: tun_chr_open\n");
  1477 + DBG1(KERN_INFO, "tunX: tun_chr_open\n");
1459 1478  
1460 1479 tfile = kmalloc(sizeof(*tfile), GFP_KERNEL);
1461 1480 if (!tfile)
... ... @@ -1476,7 +1495,7 @@
1476 1495 if (tun) {
1477 1496 struct net_device *dev = tun->dev;
1478 1497  
1479   - DBG(KERN_INFO "%s: tun_chr_close\n", dev->name);
  1498 + tun_debug(KERN_INFO, tun, "tun_chr_close\n");
1480 1499  
1481 1500 __tun_detach(tun);
1482 1501  
1483 1502  
1484 1503  
... ... @@ -1607,18 +1626,18 @@
1607 1626 {
1608 1627 int ret = 0;
1609 1628  
1610   - printk(KERN_INFO "tun: %s, %s\n", DRV_DESCRIPTION, DRV_VERSION);
1611   - printk(KERN_INFO "tun: %s\n", DRV_COPYRIGHT);
  1629 + pr_info("%s, %s\n", DRV_DESCRIPTION, DRV_VERSION);
  1630 + pr_info("%s\n", DRV_COPYRIGHT);
1612 1631  
1613 1632 ret = rtnl_link_register(&tun_link_ops);
1614 1633 if (ret) {
1615   - printk(KERN_ERR "tun: Can't register link_ops\n");
  1634 + pr_err("Can't register link_ops\n");
1616 1635 goto err_linkops;
1617 1636 }
1618 1637  
1619 1638 ret = misc_register(&tun_miscdev);
1620 1639 if (ret) {
1621   - printk(KERN_ERR "tun: Can't register misc device %d\n", TUN_MINOR);
  1640 + pr_err("Can't register misc device %d\n", TUN_MINOR);
1622 1641 goto err_misc;
1623 1642 }
1624 1643 return 0;