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

[NET_SCHED]: act_api: use PTR_ERR in tcf_action_init/tcf_action_get

Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Patrick McHardy and committed by
David S. Miller
ab27cfb8 c96c9471

+48 -41
+2 -2
include/net/act_api.h
··· 114 114 extern int tcf_unregister_action(struct tc_action_ops *a); 115 115 extern void tcf_action_destroy(struct tc_action *a, int bind); 116 116 extern int tcf_action_exec(struct sk_buff *skb, struct tc_action *a, struct tcf_result *res); 117 - extern struct tc_action *tcf_action_init(struct nlattr *nla, struct nlattr *est, char *n, int ovr, int bind, int *err); 118 - extern struct tc_action *tcf_action_init_1(struct nlattr *nla, struct nlattr *est, char *n, int ovr, int bind, int *err); 117 + extern struct tc_action *tcf_action_init(struct nlattr *nla, struct nlattr *est, char *n, int ovr, int bind); 118 + extern struct tc_action *tcf_action_init_1(struct nlattr *nla, struct nlattr *est, char *n, int ovr, int bind); 119 119 extern int tcf_action_dump(struct sk_buff *skb, struct tc_action *a, int, int); 120 120 extern int tcf_action_dump_old(struct sk_buff *skb, struct tc_action *a, int, int); 121 121 extern int tcf_action_dump_1(struct sk_buff *skb, struct tc_action *a, int, int);
+39 -32
net/sched/act_api.c
··· 18 18 #include <linux/skbuff.h> 19 19 #include <linux/init.h> 20 20 #include <linux/kmod.h> 21 + #include <linux/err.h> 21 22 #include <net/net_namespace.h> 22 23 #include <net/sock.h> 23 24 #include <net/sch_generic.h> ··· 464 463 } 465 464 466 465 struct tc_action *tcf_action_init_1(struct nlattr *nla, struct nlattr *est, 467 - char *name, int ovr, int bind, int *err) 466 + char *name, int ovr, int bind) 468 467 { 469 468 struct tc_action *a; 470 469 struct tc_action_ops *a_o; 471 470 char act_name[IFNAMSIZ]; 472 471 struct nlattr *tb[TCA_ACT_MAX+1]; 473 472 struct nlattr *kind; 473 + int err; 474 474 475 - *err = -EINVAL; 475 + err = -EINVAL; 476 476 477 477 if (name == NULL) { 478 478 if (nla_parse_nested(tb, TCA_ACT_MAX, nla, NULL) < 0) ··· 504 502 * indicate this using -EAGAIN. 505 503 */ 506 504 if (a_o != NULL) { 507 - *err = -EAGAIN; 505 + err = -EAGAIN; 508 506 goto err_mod; 509 507 } 510 508 #endif 511 - *err = -ENOENT; 509 + err = -ENOENT; 512 510 goto err_out; 513 511 } 514 512 515 - *err = -ENOMEM; 513 + err = -ENOMEM; 516 514 a = kzalloc(sizeof(*a), GFP_KERNEL); 517 515 if (a == NULL) 518 516 goto err_mod; 519 517 520 518 /* backward compatibility for policer */ 521 519 if (name == NULL) 522 - *err = a_o->init(tb[TCA_ACT_OPTIONS], est, a, ovr, bind); 520 + err = a_o->init(tb[TCA_ACT_OPTIONS], est, a, ovr, bind); 523 521 else 524 - *err = a_o->init(nla, est, a, ovr, bind); 525 - if (*err < 0) 522 + err = a_o->init(nla, est, a, ovr, bind); 523 + if (err < 0) 526 524 goto err_free; 527 525 528 526 /* module count goes up only when brand new policy is created 529 527 if it exists and is only bound to in a_o->init() then 530 528 ACT_P_CREATED is not returned (a zero is). 531 529 */ 532 - if (*err != ACT_P_CREATED) 530 + if (err != ACT_P_CREATED) 533 531 module_put(a_o->owner); 534 532 a->ops = a_o; 535 533 536 - *err = 0; 537 534 return a; 538 535 539 536 err_free: ··· 540 539 err_mod: 541 540 module_put(a_o->owner); 542 541 err_out: 543 - return NULL; 542 + return ERR_PTR(err); 544 543 } 545 544 546 545 struct tc_action *tcf_action_init(struct nlattr *nla, struct nlattr *est, 547 - char *name, int ovr, int bind, int *err) 546 + char *name, int ovr, int bind) 548 547 { 549 548 struct nlattr *tb[TCA_ACT_MAX_PRIO+1]; 550 549 struct tc_action *head = NULL, *act, *act_prev = NULL; 551 550 int i; 552 551 553 - if (nla_parse_nested(tb, TCA_ACT_MAX_PRIO, nla, NULL) < 0) { 554 - *err = -EINVAL; 555 - return head; 556 - } 552 + if (nla_parse_nested(tb, TCA_ACT_MAX_PRIO, nla, NULL) < 0) 553 + return ERR_PTR(-EINVAL); 557 554 558 555 for (i = 1; i <= TCA_ACT_MAX_PRIO && tb[i]; i++) { 559 - act = tcf_action_init_1(tb[i], est, name, ovr, bind, err); 560 - if (act == NULL) 556 + act = tcf_action_init_1(tb[i], est, name, ovr, bind); 557 + if (IS_ERR(act)) 561 558 goto err; 562 559 act->order = i; 563 560 ··· 570 571 err: 571 572 if (head != NULL) 572 573 tcf_action_destroy(head, bind); 573 - return NULL; 574 + return act; 574 575 } 575 576 576 577 int tcf_action_copy_stats(struct sk_buff *skb, struct tc_action *a, ··· 667 668 } 668 669 669 670 static struct tc_action * 670 - tcf_action_get_1(struct nlattr *nla, struct nlmsghdr *n, u32 pid, int *err) 671 + tcf_action_get_1(struct nlattr *nla, struct nlmsghdr *n, u32 pid) 671 672 { 672 673 struct nlattr *tb[TCA_ACT_MAX+1]; 673 674 struct tc_action *a; 674 675 int index; 676 + int err; 675 677 676 - *err = -EINVAL; 678 + err = -EINVAL; 677 679 if (nla_parse_nested(tb, TCA_ACT_MAX, nla, NULL) < 0) 678 - return NULL; 680 + goto err_out; 679 681 680 682 if (tb[TCA_ACT_INDEX] == NULL || 681 683 nla_len(tb[TCA_ACT_INDEX]) < sizeof(index)) 682 - return NULL; 684 + goto err_out; 683 685 index = *(int *)nla_data(tb[TCA_ACT_INDEX]); 684 686 685 - *err = -ENOMEM; 687 + err = -ENOMEM; 686 688 a = kzalloc(sizeof(struct tc_action), GFP_KERNEL); 687 689 if (a == NULL) 688 - return NULL; 690 + goto err_out; 689 691 690 - *err = -EINVAL; 692 + err = -EINVAL; 691 693 a->ops = tc_lookup_action(tb[TCA_ACT_KIND]); 692 694 if (a->ops == NULL) 693 695 goto err_free; 694 696 if (a->ops->lookup == NULL) 695 697 goto err_mod; 696 - *err = -ENOENT; 698 + err = -ENOENT; 697 699 if (a->ops->lookup(a, index) == 0) 698 700 goto err_mod; 699 701 700 702 module_put(a->ops->owner); 701 - *err = 0; 702 703 return a; 704 + 703 705 err_mod: 704 706 module_put(a->ops->owner); 705 707 err_free: 706 708 kfree(a); 707 - return NULL; 709 + err_out: 710 + return ERR_PTR(err); 708 711 } 709 712 710 713 static void cleanup_a(struct tc_action *act) ··· 817 816 } 818 817 819 818 for (i = 1; i <= TCA_ACT_MAX_PRIO && tb[i]; i++) { 820 - act = tcf_action_get_1(tb[i], n, pid, &ret); 821 - if (act == NULL) 819 + act = tcf_action_get_1(tb[i], n, pid); 820 + if (IS_ERR(act)) { 821 + ret = PTR_ERR(act); 822 822 goto err; 823 + } 823 824 act->order = i; 824 825 825 826 if (head == NULL) ··· 915 912 struct tc_action *a; 916 913 u32 seq = n->nlmsg_seq; 917 914 918 - act = tcf_action_init(nla, NULL, NULL, ovr, 0, &ret); 915 + act = tcf_action_init(nla, NULL, NULL, ovr, 0); 919 916 if (act == NULL) 920 917 goto done; 918 + if (IS_ERR(act)) { 919 + ret = PTR_ERR(act); 920 + goto done; 921 + } 921 922 922 923 /* dump then free all the actions after update; inserted policy 923 924 * stays intact
+7 -7
net/sched/cls_api.c
··· 23 23 #include <linux/init.h> 24 24 #include <linux/kmod.h> 25 25 #include <linux/netlink.h> 26 + #include <linux/err.h> 26 27 #include <net/net_namespace.h> 27 28 #include <net/sock.h> 28 29 #include <net/netlink.h> ··· 488 487 489 488 #ifdef CONFIG_NET_CLS_ACT 490 489 { 491 - int err; 492 490 struct tc_action *act; 493 491 494 492 if (map->police && tb[map->police]) { 495 493 act = tcf_action_init_1(tb[map->police], rate_tlv, 496 494 "police", TCA_ACT_NOREPLACE, 497 - TCA_ACT_BIND, &err); 498 - if (act == NULL) 499 - return err; 495 + TCA_ACT_BIND); 496 + if (IS_ERR(act)) 497 + return PTR_ERR(act); 500 498 501 499 act->type = TCA_OLD_COMPAT; 502 500 exts->action = act; 503 501 } else if (map->action && tb[map->action]) { 504 502 act = tcf_action_init(tb[map->action], rate_tlv, NULL, 505 - TCA_ACT_NOREPLACE, TCA_ACT_BIND, &err); 506 - if (act == NULL) 507 - return err; 503 + TCA_ACT_NOREPLACE, TCA_ACT_BIND); 504 + if (IS_ERR(act)) 505 + return PTR_ERR(act); 508 506 509 507 exts->action = act; 510 508 }