Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

scsi: replace obsolete NLMSG_* with type safe nlmsg_*

Signed-off-by: Hong Zhiguo <honkiko@gmail.com>
Reviewed-by: Mike Christie <michaelc@cs.wisc.edu>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Hong zhi guo and committed by
David S. Miller
e07ebea0 b96dc464

+45 -50
+2 -2
drivers/scsi/scsi_netlink.c
··· 50 50 u32 rlen; 51 51 int err, tport; 52 52 53 - while (skb->len >= NLMSG_SPACE(0)) { 53 + while (skb->len >= NLMSG_HDRLEN) { 54 54 err = 0; 55 55 56 56 nlh = nlmsg_hdr(skb); ··· 70 70 goto next_msg; 71 71 } 72 72 73 - hdr = NLMSG_DATA(nlh); 73 + hdr = nlmsg_data(nlh); 74 74 if ((hdr->version != SCSI_NL_VERSION) || 75 75 (hdr->magic != SCSI_NL_MAGIC)) { 76 76 err = -EPROTOTYPE;
+8 -13
drivers/scsi/scsi_transport_fc.c
··· 35 35 #include <scsi/scsi_transport.h> 36 36 #include <scsi/scsi_transport_fc.h> 37 37 #include <scsi/scsi_cmnd.h> 38 - #include <linux/netlink.h> 39 38 #include <net/netlink.h> 40 39 #include <scsi/scsi_netlink_fc.h> 41 40 #include <scsi/scsi_bsg_fc.h> ··· 533 534 struct nlmsghdr *nlh; 534 535 struct fc_nl_event *event; 535 536 const char *name; 536 - u32 len, skblen; 537 + u32 len; 537 538 int err; 538 539 539 540 if (!scsi_nl_sock) { ··· 542 543 } 543 544 544 545 len = FC_NL_MSGALIGN(sizeof(*event)); 545 - skblen = NLMSG_SPACE(len); 546 546 547 - skb = alloc_skb(skblen, GFP_KERNEL); 547 + skb = nlmsg_new(len, GFP_KERNEL); 548 548 if (!skb) { 549 549 err = -ENOBUFS; 550 550 goto send_fail; 551 551 } 552 552 553 - nlh = nlmsg_put(skb, 0, 0, SCSI_TRANSPORT_MSG, 554 - skblen - sizeof(*nlh), 0); 553 + nlh = nlmsg_put(skb, 0, 0, SCSI_TRANSPORT_MSG, len, 0); 555 554 if (!nlh) { 556 555 err = -ENOBUFS; 557 556 goto send_fail_skb; 558 557 } 559 - event = NLMSG_DATA(nlh); 558 + event = nlmsg_data(nlh); 560 559 561 560 INIT_SCSI_NL_HDR(&event->snlh, SCSI_NL_TRANSPORT_FC, 562 561 FC_NL_ASYNC_EVENT, len); ··· 601 604 struct sk_buff *skb; 602 605 struct nlmsghdr *nlh; 603 606 struct fc_nl_event *event; 604 - u32 len, skblen; 607 + u32 len; 605 608 int err; 606 609 607 610 if (!scsi_nl_sock) { ··· 610 613 } 611 614 612 615 len = FC_NL_MSGALIGN(sizeof(*event) + data_len); 613 - skblen = NLMSG_SPACE(len); 614 616 615 - skb = alloc_skb(skblen, GFP_KERNEL); 617 + skb = nlmsg_new(len, GFP_KERNEL); 616 618 if (!skb) { 617 619 err = -ENOBUFS; 618 620 goto send_vendor_fail; 619 621 } 620 622 621 - nlh = nlmsg_put(skb, 0, 0, SCSI_TRANSPORT_MSG, 622 - skblen - sizeof(*nlh), 0); 623 + nlh = nlmsg_put(skb, 0, 0, SCSI_TRANSPORT_MSG, len, 0); 623 624 if (!nlh) { 624 625 err = -ENOBUFS; 625 626 goto send_vendor_fail_skb; 626 627 } 627 - event = NLMSG_DATA(nlh); 628 + event = nlmsg_data(nlh); 628 629 629 630 INIT_SCSI_NL_HDR(&event->snlh, SCSI_NL_TRANSPORT_FC, 630 631 FC_NL_ASYNC_EVENT, len);
+35 -35
drivers/scsi/scsi_transport_iscsi.c
··· 1344 1344 struct iscsi_uevent *ev; 1345 1345 char *pdu; 1346 1346 struct iscsi_internal *priv; 1347 - int len = NLMSG_SPACE(sizeof(*ev) + sizeof(struct iscsi_hdr) + 1348 - data_size); 1347 + int len = nlmsg_total_size(sizeof(*ev) + sizeof(struct iscsi_hdr) + 1348 + data_size); 1349 1349 1350 1350 priv = iscsi_if_transport_lookup(conn->transport); 1351 1351 if (!priv) ··· 1360 1360 } 1361 1361 1362 1362 nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0); 1363 - ev = NLMSG_DATA(nlh); 1363 + ev = nlmsg_data(nlh); 1364 1364 memset(ev, 0, sizeof(*ev)); 1365 1365 ev->transport_handle = iscsi_handle(conn->transport); 1366 1366 ev->type = ISCSI_KEVENT_RECV_PDU; ··· 1381 1381 struct nlmsghdr *nlh; 1382 1382 struct sk_buff *skb; 1383 1383 struct iscsi_uevent *ev; 1384 - int len = NLMSG_SPACE(sizeof(*ev) + data_size); 1384 + int len = nlmsg_total_size(sizeof(*ev) + data_size); 1385 1385 1386 1386 skb = alloc_skb(len, GFP_ATOMIC); 1387 1387 if (!skb) { ··· 1390 1390 } 1391 1391 1392 1392 nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0); 1393 - ev = NLMSG_DATA(nlh); 1393 + ev = nlmsg_data(nlh); 1394 1394 memset(ev, 0, sizeof(*ev)); 1395 1395 ev->type = type; 1396 1396 ev->transport_handle = iscsi_handle(transport); ··· 1415 1415 struct sk_buff *skb; 1416 1416 struct iscsi_uevent *ev; 1417 1417 struct iscsi_internal *priv; 1418 - int len = NLMSG_SPACE(sizeof(*ev)); 1418 + int len = nlmsg_total_size(sizeof(*ev)); 1419 1419 1420 1420 priv = iscsi_if_transport_lookup(conn->transport); 1421 1421 if (!priv) ··· 1429 1429 } 1430 1430 1431 1431 nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0); 1432 - ev = NLMSG_DATA(nlh); 1432 + ev = nlmsg_data(nlh); 1433 1433 ev->transport_handle = iscsi_handle(conn->transport); 1434 1434 ev->type = ISCSI_KEVENT_CONN_ERROR; 1435 1435 ev->r.connerror.error = error; ··· 1450 1450 struct sk_buff *skb; 1451 1451 struct iscsi_uevent *ev; 1452 1452 struct iscsi_internal *priv; 1453 - int len = NLMSG_SPACE(sizeof(*ev)); 1453 + int len = nlmsg_total_size(sizeof(*ev)); 1454 1454 1455 1455 priv = iscsi_if_transport_lookup(conn->transport); 1456 1456 if (!priv) ··· 1464 1464 } 1465 1465 1466 1466 nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0); 1467 - ev = NLMSG_DATA(nlh); 1467 + ev = nlmsg_data(nlh); 1468 1468 ev->transport_handle = iscsi_handle(conn->transport); 1469 1469 ev->type = ISCSI_KEVENT_CONN_LOGIN_STATE; 1470 1470 ev->r.conn_login.state = state; ··· 1484 1484 struct nlmsghdr *nlh; 1485 1485 struct sk_buff *skb; 1486 1486 struct iscsi_uevent *ev; 1487 - int len = NLMSG_SPACE(sizeof(*ev) + data_size); 1487 + int len = nlmsg_total_size(sizeof(*ev) + data_size); 1488 1488 1489 1489 skb = alloc_skb(len, GFP_NOIO); 1490 1490 if (!skb) { ··· 1494 1494 } 1495 1495 1496 1496 nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0); 1497 - ev = NLMSG_DATA(nlh); 1497 + ev = nlmsg_data(nlh); 1498 1498 ev->transport_handle = iscsi_handle(transport); 1499 1499 ev->type = ISCSI_KEVENT_HOST_EVENT; 1500 1500 ev->r.host_event.host_no = host_no; ··· 1515 1515 struct nlmsghdr *nlh; 1516 1516 struct sk_buff *skb; 1517 1517 struct iscsi_uevent *ev; 1518 - int len = NLMSG_SPACE(sizeof(*ev) + data_size); 1518 + int len = nlmsg_total_size(sizeof(*ev) + data_size); 1519 1519 1520 1520 skb = alloc_skb(len, GFP_NOIO); 1521 1521 if (!skb) { ··· 1524 1524 } 1525 1525 1526 1526 nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0); 1527 - ev = NLMSG_DATA(nlh); 1527 + ev = nlmsg_data(nlh); 1528 1528 ev->transport_handle = iscsi_handle(transport); 1529 1529 ev->type = ISCSI_KEVENT_PING_COMP; 1530 1530 ev->r.ping_comp.host_no = host_no; ··· 1543 1543 { 1544 1544 struct sk_buff *skb; 1545 1545 struct nlmsghdr *nlh; 1546 - int len = NLMSG_SPACE(size); 1546 + int len = nlmsg_total_size(size); 1547 1547 int flags = multi ? NLM_F_MULTI : 0; 1548 1548 int t = done ? NLMSG_DONE : type; 1549 1549 ··· 1555 1555 1556 1556 nlh = __nlmsg_put(skb, 0, 0, t, (len - sizeof(*nlh)), 0); 1557 1557 nlh->nlmsg_flags = flags; 1558 - memcpy(NLMSG_DATA(nlh), payload, size); 1558 + memcpy(nlmsg_data(nlh), payload, size); 1559 1559 return iscsi_multicast_skb(skb, group, GFP_ATOMIC); 1560 1560 } 1561 1561 1562 1562 static int 1563 1563 iscsi_if_get_stats(struct iscsi_transport *transport, struct nlmsghdr *nlh) 1564 1564 { 1565 - struct iscsi_uevent *ev = NLMSG_DATA(nlh); 1565 + struct iscsi_uevent *ev = nlmsg_data(nlh); 1566 1566 struct iscsi_stats *stats; 1567 1567 struct sk_buff *skbstat; 1568 1568 struct iscsi_cls_conn *conn; 1569 1569 struct nlmsghdr *nlhstat; 1570 1570 struct iscsi_uevent *evstat; 1571 1571 struct iscsi_internal *priv; 1572 - int len = NLMSG_SPACE(sizeof(*ev) + 1573 - sizeof(struct iscsi_stats) + 1574 - sizeof(struct iscsi_stats_custom) * 1575 - ISCSI_STATS_CUSTOM_MAX); 1572 + int len = nlmsg_total_size(sizeof(*ev) + 1573 + sizeof(struct iscsi_stats) + 1574 + sizeof(struct iscsi_stats_custom) * 1575 + ISCSI_STATS_CUSTOM_MAX); 1576 1576 int err = 0; 1577 1577 1578 1578 priv = iscsi_if_transport_lookup(transport); ··· 1595 1595 1596 1596 nlhstat = __nlmsg_put(skbstat, 0, 0, 0, 1597 1597 (len - sizeof(*nlhstat)), 0); 1598 - evstat = NLMSG_DATA(nlhstat); 1598 + evstat = nlmsg_data(nlhstat); 1599 1599 memset(evstat, 0, sizeof(*evstat)); 1600 1600 evstat->transport_handle = iscsi_handle(conn->transport); 1601 1601 evstat->type = nlh->nlmsg_type; ··· 1608 1608 memset(stats, 0, sizeof(*stats)); 1609 1609 1610 1610 transport->get_stats(conn, stats); 1611 - actual_size = NLMSG_SPACE(sizeof(struct iscsi_uevent) + 1612 - sizeof(struct iscsi_stats) + 1613 - sizeof(struct iscsi_stats_custom) * 1614 - stats->custom_length); 1611 + actual_size = nlmsg_total_size(sizeof(struct iscsi_uevent) + 1612 + sizeof(struct iscsi_stats) + 1613 + sizeof(struct iscsi_stats_custom) * 1614 + stats->custom_length); 1615 1615 actual_size -= sizeof(*nlhstat); 1616 - actual_size = NLMSG_LENGTH(actual_size); 1616 + actual_size = nlmsg_msg_size(actual_size); 1617 1617 skb_trim(skbstat, NLMSG_ALIGN(actual_size)); 1618 1618 nlhstat->nlmsg_len = actual_size; 1619 1619 ··· 1637 1637 struct iscsi_uevent *ev; 1638 1638 struct sk_buff *skb; 1639 1639 struct nlmsghdr *nlh; 1640 - int rc, len = NLMSG_SPACE(sizeof(*ev)); 1640 + int rc, len = nlmsg_total_size(sizeof(*ev)); 1641 1641 1642 1642 priv = iscsi_if_transport_lookup(session->transport); 1643 1643 if (!priv) ··· 1653 1653 } 1654 1654 1655 1655 nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0); 1656 - ev = NLMSG_DATA(nlh); 1656 + ev = nlmsg_data(nlh); 1657 1657 ev->transport_handle = iscsi_handle(session->transport); 1658 1658 1659 1659 ev->type = event; ··· 2005 2005 static int 2006 2006 iscsi_get_chap(struct iscsi_transport *transport, struct nlmsghdr *nlh) 2007 2007 { 2008 - struct iscsi_uevent *ev = NLMSG_DATA(nlh); 2008 + struct iscsi_uevent *ev = nlmsg_data(nlh); 2009 2009 struct Scsi_Host *shost = NULL; 2010 2010 struct iscsi_chap_rec *chap_rec; 2011 2011 struct iscsi_internal *priv; ··· 2024 2024 return -EINVAL; 2025 2025 2026 2026 chap_buf_size = (ev->u.get_chap.num_entries * sizeof(*chap_rec)); 2027 - len = NLMSG_SPACE(sizeof(*ev) + chap_buf_size); 2027 + len = nlmsg_total_size(sizeof(*ev) + chap_buf_size); 2028 2028 2029 2029 shost = scsi_host_lookup(ev->u.get_chap.host_no); 2030 2030 if (!shost) { ··· 2045 2045 2046 2046 nlhchap = __nlmsg_put(skbchap, 0, 0, 0, 2047 2047 (len - sizeof(*nlhchap)), 0); 2048 - evchap = NLMSG_DATA(nlhchap); 2048 + evchap = nlmsg_data(nlhchap); 2049 2049 memset(evchap, 0, sizeof(*evchap)); 2050 2050 evchap->transport_handle = iscsi_handle(transport); 2051 2051 evchap->type = nlh->nlmsg_type; ··· 2058 2058 err = transport->get_chap(shost, ev->u.get_chap.chap_tbl_idx, 2059 2059 &evchap->u.get_chap.num_entries, buf); 2060 2060 2061 - actual_size = NLMSG_SPACE(sizeof(*ev) + chap_buf_size); 2061 + actual_size = nlmsg_total_size(sizeof(*ev) + chap_buf_size); 2062 2062 skb_trim(skbchap, NLMSG_ALIGN(actual_size)); 2063 2063 nlhchap->nlmsg_len = actual_size; 2064 2064 ··· 2096 2096 iscsi_if_recv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, uint32_t *group) 2097 2097 { 2098 2098 int err = 0; 2099 - struct iscsi_uevent *ev = NLMSG_DATA(nlh); 2099 + struct iscsi_uevent *ev = nlmsg_data(nlh); 2100 2100 struct iscsi_transport *transport = NULL; 2101 2101 struct iscsi_internal *priv; 2102 2102 struct iscsi_cls_session *session; ··· 2263 2263 iscsi_if_rx(struct sk_buff *skb) 2264 2264 { 2265 2265 mutex_lock(&rx_queue_mutex); 2266 - while (skb->len >= NLMSG_SPACE(0)) { 2266 + while (skb->len >= NLMSG_HDRLEN) { 2267 2267 int err; 2268 2268 uint32_t rlen; 2269 2269 struct nlmsghdr *nlh; ··· 2276 2276 break; 2277 2277 } 2278 2278 2279 - ev = NLMSG_DATA(nlh); 2279 + ev = nlmsg_data(nlh); 2280 2280 rlen = NLMSG_ALIGN(nlh->nlmsg_len); 2281 2281 if (rlen > skb->len) 2282 2282 rlen = skb->len;