Skip to content

Commit e07ebea

Browse files
honkikodavem330
authored andcommitted
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>
1 parent b96dc46 commit e07ebea

3 files changed

Lines changed: 45 additions & 50 deletions

File tree

‎drivers/scsi/scsi_netlink.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ scsi_nl_rcv_msg(struct sk_buff *skb)
5050
u32 rlen;
5151
int err, tport;
5252

53-
while (skb->len >= NLMSG_SPACE(0)) {
53+
while (skb->len >= NLMSG_HDRLEN) {
5454
err = 0;
5555

5656
nlh = nlmsg_hdr(skb);
@@ -70,7 +70,7 @@ scsi_nl_rcv_msg(struct sk_buff *skb)
7070
goto next_msg;
7171
}
7272

73-
hdr = NLMSG_DATA(nlh);
73+
hdr = nlmsg_data(nlh);
7474
if ((hdr->version != SCSI_NL_VERSION) ||
7575
(hdr->magic != SCSI_NL_MAGIC)) {
7676
err = -EPROTOTYPE;

‎drivers/scsi/scsi_transport_fc.c‎

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
#include <scsi/scsi_transport.h>
3636
#include <scsi/scsi_transport_fc.h>
3737
#include <scsi/scsi_cmnd.h>
38-
#include <linux/netlink.h>
3938
#include <net/netlink.h>
4039
#include <scsi/scsi_netlink_fc.h>
4140
#include <scsi/scsi_bsg_fc.h>
@@ -534,7 +533,7 @@ fc_host_post_event(struct Scsi_Host *shost, u32 event_number,
534533
struct nlmsghdr *nlh;
535534
struct fc_nl_event *event;
536535
const char *name;
537-
u32 len, skblen;
536+
u32 len;
538537
int err;
539538

540539
if (!scsi_nl_sock) {
@@ -543,21 +542,19 @@ fc_host_post_event(struct Scsi_Host *shost, u32 event_number,
543542
}
544543

545544
len = FC_NL_MSGALIGN(sizeof(*event));
546-
skblen = NLMSG_SPACE(len);
547545

548-
skb = alloc_skb(skblen, GFP_KERNEL);
546+
skb = nlmsg_new(len, GFP_KERNEL);
549547
if (!skb) {
550548
err = -ENOBUFS;
551549
goto send_fail;
552550
}
553551

554-
nlh = nlmsg_put(skb, 0, 0, SCSI_TRANSPORT_MSG,
555-
skblen - sizeof(*nlh), 0);
552+
nlh = nlmsg_put(skb, 0, 0, SCSI_TRANSPORT_MSG, len, 0);
556553
if (!nlh) {
557554
err = -ENOBUFS;
558555
goto send_fail_skb;
559556
}
560-
event = NLMSG_DATA(nlh);
557+
event = nlmsg_data(nlh);
561558

562559
INIT_SCSI_NL_HDR(&event->snlh, SCSI_NL_TRANSPORT_FC,
563560
FC_NL_ASYNC_EVENT, len);
@@ -604,7 +601,7 @@ fc_host_post_vendor_event(struct Scsi_Host *shost, u32 event_number,
604601
struct sk_buff *skb;
605602
struct nlmsghdr *nlh;
606603
struct fc_nl_event *event;
607-
u32 len, skblen;
604+
u32 len;
608605
int err;
609606

610607
if (!scsi_nl_sock) {
@@ -613,21 +610,19 @@ fc_host_post_vendor_event(struct Scsi_Host *shost, u32 event_number,
613610
}
614611

615612
len = FC_NL_MSGALIGN(sizeof(*event) + data_len);
616-
skblen = NLMSG_SPACE(len);
617613

618-
skb = alloc_skb(skblen, GFP_KERNEL);
614+
skb = nlmsg_new(len, GFP_KERNEL);
619615
if (!skb) {
620616
err = -ENOBUFS;
621617
goto send_vendor_fail;
622618
}
623619

624-
nlh = nlmsg_put(skb, 0, 0, SCSI_TRANSPORT_MSG,
625-
skblen - sizeof(*nlh), 0);
620+
nlh = nlmsg_put(skb, 0, 0, SCSI_TRANSPORT_MSG, len, 0);
626621
if (!nlh) {
627622
err = -ENOBUFS;
628623
goto send_vendor_fail_skb;
629624
}
630-
event = NLMSG_DATA(nlh);
625+
event = nlmsg_data(nlh);
631626

632627
INIT_SCSI_NL_HDR(&event->snlh, SCSI_NL_TRANSPORT_FC,
633628
FC_NL_ASYNC_EVENT, len);

‎drivers/scsi/scsi_transport_iscsi.c‎

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,8 +1344,8 @@ int iscsi_recv_pdu(struct iscsi_cls_conn *conn, struct iscsi_hdr *hdr,
13441344
struct iscsi_uevent *ev;
13451345
char *pdu;
13461346
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);
13491349

13501350
priv = iscsi_if_transport_lookup(conn->transport);
13511351
if (!priv)
@@ -1360,7 +1360,7 @@ int iscsi_recv_pdu(struct iscsi_cls_conn *conn, struct iscsi_hdr *hdr,
13601360
}
13611361

13621362
nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0);
1363-
ev = NLMSG_DATA(nlh);
1363+
ev = nlmsg_data(nlh);
13641364
memset(ev, 0, sizeof(*ev));
13651365
ev->transport_handle = iscsi_handle(conn->transport);
13661366
ev->type = ISCSI_KEVENT_RECV_PDU;
@@ -1381,7 +1381,7 @@ int iscsi_offload_mesg(struct Scsi_Host *shost,
13811381
struct nlmsghdr *nlh;
13821382
struct sk_buff *skb;
13831383
struct iscsi_uevent *ev;
1384-
int len = NLMSG_SPACE(sizeof(*ev) + data_size);
1384+
int len = nlmsg_total_size(sizeof(*ev) + data_size);
13851385

13861386
skb = alloc_skb(len, GFP_ATOMIC);
13871387
if (!skb) {
@@ -1390,7 +1390,7 @@ int iscsi_offload_mesg(struct Scsi_Host *shost,
13901390
}
13911391

13921392
nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0);
1393-
ev = NLMSG_DATA(nlh);
1393+
ev = nlmsg_data(nlh);
13941394
memset(ev, 0, sizeof(*ev));
13951395
ev->type = type;
13961396
ev->transport_handle = iscsi_handle(transport);
@@ -1415,7 +1415,7 @@ void iscsi_conn_error_event(struct iscsi_cls_conn *conn, enum iscsi_err error)
14151415
struct sk_buff *skb;
14161416
struct iscsi_uevent *ev;
14171417
struct iscsi_internal *priv;
1418-
int len = NLMSG_SPACE(sizeof(*ev));
1418+
int len = nlmsg_total_size(sizeof(*ev));
14191419

14201420
priv = iscsi_if_transport_lookup(conn->transport);
14211421
if (!priv)
@@ -1429,7 +1429,7 @@ void iscsi_conn_error_event(struct iscsi_cls_conn *conn, enum iscsi_err error)
14291429
}
14301430

14311431
nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0);
1432-
ev = NLMSG_DATA(nlh);
1432+
ev = nlmsg_data(nlh);
14331433
ev->transport_handle = iscsi_handle(conn->transport);
14341434
ev->type = ISCSI_KEVENT_CONN_ERROR;
14351435
ev->r.connerror.error = error;
@@ -1450,7 +1450,7 @@ void iscsi_conn_login_event(struct iscsi_cls_conn *conn,
14501450
struct sk_buff *skb;
14511451
struct iscsi_uevent *ev;
14521452
struct iscsi_internal *priv;
1453-
int len = NLMSG_SPACE(sizeof(*ev));
1453+
int len = nlmsg_total_size(sizeof(*ev));
14541454

14551455
priv = iscsi_if_transport_lookup(conn->transport);
14561456
if (!priv)
@@ -1464,7 +1464,7 @@ void iscsi_conn_login_event(struct iscsi_cls_conn *conn,
14641464
}
14651465

14661466
nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0);
1467-
ev = NLMSG_DATA(nlh);
1467+
ev = nlmsg_data(nlh);
14681468
ev->transport_handle = iscsi_handle(conn->transport);
14691469
ev->type = ISCSI_KEVENT_CONN_LOGIN_STATE;
14701470
ev->r.conn_login.state = state;
@@ -1484,7 +1484,7 @@ void iscsi_post_host_event(uint32_t host_no, struct iscsi_transport *transport,
14841484
struct nlmsghdr *nlh;
14851485
struct sk_buff *skb;
14861486
struct iscsi_uevent *ev;
1487-
int len = NLMSG_SPACE(sizeof(*ev) + data_size);
1487+
int len = nlmsg_total_size(sizeof(*ev) + data_size);
14881488

14891489
skb = alloc_skb(len, GFP_NOIO);
14901490
if (!skb) {
@@ -1494,7 +1494,7 @@ void iscsi_post_host_event(uint32_t host_no, struct iscsi_transport *transport,
14941494
}
14951495

14961496
nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0);
1497-
ev = NLMSG_DATA(nlh);
1497+
ev = nlmsg_data(nlh);
14981498
ev->transport_handle = iscsi_handle(transport);
14991499
ev->type = ISCSI_KEVENT_HOST_EVENT;
15001500
ev->r.host_event.host_no = host_no;
@@ -1515,7 +1515,7 @@ void iscsi_ping_comp_event(uint32_t host_no, struct iscsi_transport *transport,
15151515
struct nlmsghdr *nlh;
15161516
struct sk_buff *skb;
15171517
struct iscsi_uevent *ev;
1518-
int len = NLMSG_SPACE(sizeof(*ev) + data_size);
1518+
int len = nlmsg_total_size(sizeof(*ev) + data_size);
15191519

15201520
skb = alloc_skb(len, GFP_NOIO);
15211521
if (!skb) {
@@ -1524,7 +1524,7 @@ void iscsi_ping_comp_event(uint32_t host_no, struct iscsi_transport *transport,
15241524
}
15251525

15261526
nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0);
1527-
ev = NLMSG_DATA(nlh);
1527+
ev = nlmsg_data(nlh);
15281528
ev->transport_handle = iscsi_handle(transport);
15291529
ev->type = ISCSI_KEVENT_PING_COMP;
15301530
ev->r.ping_comp.host_no = host_no;
@@ -1543,7 +1543,7 @@ iscsi_if_send_reply(uint32_t group, int seq, int type, int done, int multi,
15431543
{
15441544
struct sk_buff *skb;
15451545
struct nlmsghdr *nlh;
1546-
int len = NLMSG_SPACE(size);
1546+
int len = nlmsg_total_size(size);
15471547
int flags = multi ? NLM_F_MULTI : 0;
15481548
int t = done ? NLMSG_DONE : type;
15491549

@@ -1555,24 +1555,24 @@ iscsi_if_send_reply(uint32_t group, int seq, int type, int done, int multi,
15551555

15561556
nlh = __nlmsg_put(skb, 0, 0, t, (len - sizeof(*nlh)), 0);
15571557
nlh->nlmsg_flags = flags;
1558-
memcpy(NLMSG_DATA(nlh), payload, size);
1558+
memcpy(nlmsg_data(nlh), payload, size);
15591559
return iscsi_multicast_skb(skb, group, GFP_ATOMIC);
15601560
}
15611561

15621562
static int
15631563
iscsi_if_get_stats(struct iscsi_transport *transport, struct nlmsghdr *nlh)
15641564
{
1565-
struct iscsi_uevent *ev = NLMSG_DATA(nlh);
1565+
struct iscsi_uevent *ev = nlmsg_data(nlh);
15661566
struct iscsi_stats *stats;
15671567
struct sk_buff *skbstat;
15681568
struct iscsi_cls_conn *conn;
15691569
struct nlmsghdr *nlhstat;
15701570
struct iscsi_uevent *evstat;
15711571
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);
15761576
int err = 0;
15771577

15781578
priv = iscsi_if_transport_lookup(transport);
@@ -1595,7 +1595,7 @@ iscsi_if_get_stats(struct iscsi_transport *transport, struct nlmsghdr *nlh)
15951595

15961596
nlhstat = __nlmsg_put(skbstat, 0, 0, 0,
15971597
(len - sizeof(*nlhstat)), 0);
1598-
evstat = NLMSG_DATA(nlhstat);
1598+
evstat = nlmsg_data(nlhstat);
15991599
memset(evstat, 0, sizeof(*evstat));
16001600
evstat->transport_handle = iscsi_handle(conn->transport);
16011601
evstat->type = nlh->nlmsg_type;
@@ -1608,12 +1608,12 @@ iscsi_if_get_stats(struct iscsi_transport *transport, struct nlmsghdr *nlh)
16081608
memset(stats, 0, sizeof(*stats));
16091609

16101610
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);
16151615
actual_size -= sizeof(*nlhstat);
1616-
actual_size = NLMSG_LENGTH(actual_size);
1616+
actual_size = nlmsg_msg_size(actual_size);
16171617
skb_trim(skbstat, NLMSG_ALIGN(actual_size));
16181618
nlhstat->nlmsg_len = actual_size;
16191619

@@ -1637,7 +1637,7 @@ int iscsi_session_event(struct iscsi_cls_session *session,
16371637
struct iscsi_uevent *ev;
16381638
struct sk_buff *skb;
16391639
struct nlmsghdr *nlh;
1640-
int rc, len = NLMSG_SPACE(sizeof(*ev));
1640+
int rc, len = nlmsg_total_size(sizeof(*ev));
16411641

16421642
priv = iscsi_if_transport_lookup(session->transport);
16431643
if (!priv)
@@ -1653,7 +1653,7 @@ int iscsi_session_event(struct iscsi_cls_session *session,
16531653
}
16541654

16551655
nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0);
1656-
ev = NLMSG_DATA(nlh);
1656+
ev = nlmsg_data(nlh);
16571657
ev->transport_handle = iscsi_handle(session->transport);
16581658

16591659
ev->type = event;
@@ -2005,7 +2005,7 @@ iscsi_send_ping(struct iscsi_transport *transport, struct iscsi_uevent *ev)
20052005
static int
20062006
iscsi_get_chap(struct iscsi_transport *transport, struct nlmsghdr *nlh)
20072007
{
2008-
struct iscsi_uevent *ev = NLMSG_DATA(nlh);
2008+
struct iscsi_uevent *ev = nlmsg_data(nlh);
20092009
struct Scsi_Host *shost = NULL;
20102010
struct iscsi_chap_rec *chap_rec;
20112011
struct iscsi_internal *priv;
@@ -2024,7 +2024,7 @@ iscsi_get_chap(struct iscsi_transport *transport, struct nlmsghdr *nlh)
20242024
return -EINVAL;
20252025

20262026
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);
20282028

20292029
shost = scsi_host_lookup(ev->u.get_chap.host_no);
20302030
if (!shost) {
@@ -2045,7 +2045,7 @@ iscsi_get_chap(struct iscsi_transport *transport, struct nlmsghdr *nlh)
20452045

20462046
nlhchap = __nlmsg_put(skbchap, 0, 0, 0,
20472047
(len - sizeof(*nlhchap)), 0);
2048-
evchap = NLMSG_DATA(nlhchap);
2048+
evchap = nlmsg_data(nlhchap);
20492049
memset(evchap, 0, sizeof(*evchap));
20502050
evchap->transport_handle = iscsi_handle(transport);
20512051
evchap->type = nlh->nlmsg_type;
@@ -2058,7 +2058,7 @@ iscsi_get_chap(struct iscsi_transport *transport, struct nlmsghdr *nlh)
20582058
err = transport->get_chap(shost, ev->u.get_chap.chap_tbl_idx,
20592059
&evchap->u.get_chap.num_entries, buf);
20602060

2061-
actual_size = NLMSG_SPACE(sizeof(*ev) + chap_buf_size);
2061+
actual_size = nlmsg_total_size(sizeof(*ev) + chap_buf_size);
20622062
skb_trim(skbchap, NLMSG_ALIGN(actual_size));
20632063
nlhchap->nlmsg_len = actual_size;
20642064

@@ -2096,7 +2096,7 @@ static int
20962096
iscsi_if_recv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, uint32_t *group)
20972097
{
20982098
int err = 0;
2099-
struct iscsi_uevent *ev = NLMSG_DATA(nlh);
2099+
struct iscsi_uevent *ev = nlmsg_data(nlh);
21002100
struct iscsi_transport *transport = NULL;
21012101
struct iscsi_internal *priv;
21022102
struct iscsi_cls_session *session;
@@ -2263,7 +2263,7 @@ static void
22632263
iscsi_if_rx(struct sk_buff *skb)
22642264
{
22652265
mutex_lock(&rx_queue_mutex);
2266-
while (skb->len >= NLMSG_SPACE(0)) {
2266+
while (skb->len >= NLMSG_HDRLEN) {
22672267
int err;
22682268
uint32_t rlen;
22692269
struct nlmsghdr *nlh;
@@ -2276,7 +2276,7 @@ iscsi_if_rx(struct sk_buff *skb)
22762276
break;
22772277
}
22782278

2279-
ev = NLMSG_DATA(nlh);
2279+
ev = nlmsg_data(nlh);
22802280
rlen = NLMSG_ALIGN(nlh->nlmsg_len);
22812281
if (rlen > skb->len)
22822282
rlen = skb->len;

0 commit comments

Comments
 (0)