@@ -251,15 +251,16 @@ static int hsr_get_node_status(struct sk_buff *skb_in, struct genl_info *info)
251
251
if (!na )
252
252
goto invalid ;
253
253
254
- hsr_dev = __dev_get_by_index (genl_info_net (info ),
255
- nla_get_u32 (info -> attrs [HSR_A_IFINDEX ]));
254
+ rcu_read_lock ();
255
+ hsr_dev = dev_get_by_index_rcu (genl_info_net (info ),
256
+ nla_get_u32 (info -> attrs [HSR_A_IFINDEX ]));
256
257
if (!hsr_dev )
257
- goto invalid ;
258
+ goto rcu_unlock ;
258
259
if (!is_hsr_master (hsr_dev ))
259
- goto invalid ;
260
+ goto rcu_unlock ;
260
261
261
262
/* Send reply */
262
- skb_out = genlmsg_new (NLMSG_GOODSIZE , GFP_KERNEL );
263
+ skb_out = genlmsg_new (NLMSG_GOODSIZE , GFP_ATOMIC );
263
264
if (!skb_out ) {
264
265
res = - ENOMEM ;
265
266
goto fail ;
@@ -313,12 +314,10 @@ static int hsr_get_node_status(struct sk_buff *skb_in, struct genl_info *info)
313
314
res = nla_put_u16 (skb_out , HSR_A_IF1_SEQ , hsr_node_if1_seq );
314
315
if (res < 0 )
315
316
goto nla_put_failure ;
316
- rcu_read_lock ();
317
317
port = hsr_port_get_hsr (hsr , HSR_PT_SLAVE_A );
318
318
if (port )
319
319
res = nla_put_u32 (skb_out , HSR_A_IF1_IFINDEX ,
320
320
port -> dev -> ifindex );
321
- rcu_read_unlock ();
322
321
if (res < 0 )
323
322
goto nla_put_failure ;
324
323
@@ -328,20 +327,22 @@ static int hsr_get_node_status(struct sk_buff *skb_in, struct genl_info *info)
328
327
res = nla_put_u16 (skb_out , HSR_A_IF2_SEQ , hsr_node_if2_seq );
329
328
if (res < 0 )
330
329
goto nla_put_failure ;
331
- rcu_read_lock ();
332
330
port = hsr_port_get_hsr (hsr , HSR_PT_SLAVE_B );
333
331
if (port )
334
332
res = nla_put_u32 (skb_out , HSR_A_IF2_IFINDEX ,
335
333
port -> dev -> ifindex );
336
- rcu_read_unlock ();
337
334
if (res < 0 )
338
335
goto nla_put_failure ;
339
336
337
+ rcu_read_unlock ();
338
+
340
339
genlmsg_end (skb_out , msg_head );
341
340
genlmsg_unicast (genl_info_net (info ), skb_out , info -> snd_portid );
342
341
343
342
return 0 ;
344
343
344
+ rcu_unlock :
345
+ rcu_read_unlock ();
345
346
invalid :
346
347
netlink_ack (skb_in , nlmsg_hdr (skb_in ), - EINVAL , NULL );
347
348
return 0 ;
@@ -351,6 +352,7 @@ static int hsr_get_node_status(struct sk_buff *skb_in, struct genl_info *info)
351
352
/* Fall through */
352
353
353
354
fail :
355
+ rcu_read_unlock ();
354
356
return res ;
355
357
}
356
358
@@ -377,15 +379,16 @@ static int hsr_get_node_list(struct sk_buff *skb_in, struct genl_info *info)
377
379
if (!na )
378
380
goto invalid ;
379
381
380
- hsr_dev = __dev_get_by_index (genl_info_net (info ),
381
- nla_get_u32 (info -> attrs [HSR_A_IFINDEX ]));
382
+ rcu_read_lock ();
383
+ hsr_dev = dev_get_by_index_rcu (genl_info_net (info ),
384
+ nla_get_u32 (info -> attrs [HSR_A_IFINDEX ]));
382
385
if (!hsr_dev )
383
- goto invalid ;
386
+ goto rcu_unlock ;
384
387
if (!is_hsr_master (hsr_dev ))
385
- goto invalid ;
388
+ goto rcu_unlock ;
386
389
387
390
/* Send reply */
388
- skb_out = genlmsg_new (NLMSG_GOODSIZE , GFP_KERNEL );
391
+ skb_out = genlmsg_new (NLMSG_GOODSIZE , GFP_ATOMIC );
389
392
if (!skb_out ) {
390
393
res = - ENOMEM ;
391
394
goto fail ;
@@ -405,14 +408,11 @@ static int hsr_get_node_list(struct sk_buff *skb_in, struct genl_info *info)
405
408
406
409
hsr = netdev_priv (hsr_dev );
407
410
408
- rcu_read_lock ();
409
411
pos = hsr_get_next_node (hsr , NULL , addr );
410
412
while (pos ) {
411
413
res = nla_put (skb_out , HSR_A_NODE_ADDR , ETH_ALEN , addr );
412
- if (res < 0 ) {
413
- rcu_read_unlock ();
414
+ if (res < 0 )
414
415
goto nla_put_failure ;
415
- }
416
416
pos = hsr_get_next_node (hsr , pos , addr );
417
417
}
418
418
rcu_read_unlock ();
@@ -422,6 +422,8 @@ static int hsr_get_node_list(struct sk_buff *skb_in, struct genl_info *info)
422
422
423
423
return 0 ;
424
424
425
+ rcu_unlock :
426
+ rcu_read_unlock ();
425
427
invalid :
426
428
netlink_ack (skb_in , nlmsg_hdr (skb_in ), - EINVAL , NULL );
427
429
return 0 ;
@@ -431,6 +433,7 @@ static int hsr_get_node_list(struct sk_buff *skb_in, struct genl_info *info)
431
433
/* Fall through */
432
434
433
435
fail :
436
+ rcu_read_unlock ();
434
437
return res ;
435
438
}
436
439
0 commit comments