Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp184083ybl; Thu, 29 Aug 2019 21:12:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqzmNwPOk9EF4bPybVufQ7u8CPia3XTBK7laB1F1NcIqF8VnXeo1GKgo49l+r9Hy4amsJiXn X-Received: by 2002:a65:430a:: with SMTP id j10mr9708075pgq.374.1567138341873; Thu, 29 Aug 2019 21:12:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567138341; cv=none; d=google.com; s=arc-20160816; b=S/Z+dXZGH/6HL0e9dvYKM2yxjOGv+YEt9XmDGyTaNjvkQ0xY0JXVzQdlV0JGPdwa5T 0leRyPT+lPZBPoocL9yuqP9BJ7fJ0oPLPTG16mCcpdhMD5Yw1bmh5OXXWDiEwG2ZmMhL XGKHsI5LlcKXpX+UjNfmOp5sqvFxJLM71lIr/UUOpN7Ts7xEhDeyOFsz+UikeNigtJ4K C2qGvUu/jYXvONQpMdlHZypLrM5gd6pbtzawGtPz+1plAJX/azEbx6icnpcueTJbHwex kSMJ+2eiJp6ibAZoRcAWWdq2drCxE5nZJZxzC1cLd2ake73ziwXYZpbXZWZLWMdaATgV ZFAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=2QpDgwtXbRlIeeoN/YyaE7pXLAKGVBx04bk85bqnlBE=; b=uR4HZmt0k7uy0SKCjq7jVDfDNoJfp8QgOfRU0MPIsaZzYkZ+5XuzcWqVSB76U6sRMI h0o2T1uoss5CQWYvDLtrqPNkwADnjbKn5bsp7olKTNpd8KG4HotyttWs4tbo5vlSJ/lB 9+ZHQ92pZoh/DfT9RG7qX0hHtVJwEsWmSu4/axow3284VjFywAQFl9WbU6g6iovHB8ME bPGy7Qojy+kN+8gd3OUHWK1XH9qiNfAd5FCdvoj9z9oeU5Tolbef/mAXFs8gNkP5Gcdj fbJMuR6d4Xw5x8S4oaFalSo3VVsAVv99MxJ2NqjcoQegz/vUVooLeJO54lEcwBfeA7dg 2nTw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mellanox.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k91si3685123pld.335.2019.08.29.21.12.06; Thu, 29 Aug 2019 21:12:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mellanox.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726495AbfH3EKv (ORCPT + 99 others); Fri, 30 Aug 2019 00:10:51 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:42721 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726144AbfH3EKu (ORCPT ); Fri, 30 Aug 2019 00:10:50 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from parav@mellanox.com) with ESMTPS (AES256-SHA encrypted); 30 Aug 2019 07:10:47 +0300 Received: from sw-mtx-036.mtx.labs.mlnx (sw-mtx-036.mtx.labs.mlnx [10.12.150.149]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id x7U4AiDB010368; Fri, 30 Aug 2019 07:10:47 +0300 From: Parav Pandit To: linux-kernel@vger.kernel.org, jiri@mellanox.com Cc: Parav Pandit Subject: [PATCH internal net-next 2/2] devlink: Use switch-case instead of if-else Date: Thu, 29 Aug 2019 23:10:35 -0500 Message-Id: <20190830041035.60581-3-parav@mellanox.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190830041035.60581-1-parav@mellanox.com> References: <20190830041035.60581-1-parav@mellanox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Make core more readable with switch-case for various port flavours. Signed-off-by: Parav Pandit --- net/core/devlink.c | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/net/core/devlink.c b/net/core/devlink.c index b7091329987a..6e52d639dac6 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -510,32 +510,37 @@ static int devlink_nl_port_attrs_put(struct sk_buff *msg, return 0; if (nla_put_u16(msg, DEVLINK_ATTR_PORT_FLAVOUR, attrs->flavour)) return -EMSGSIZE; - if (devlink_port->attrs.flavour == DEVLINK_PORT_FLAVOUR_PCI_PF) { + switch (devlink_port->attrs.flavour) { + case DEVLINK_PORT_FLAVOUR_PCI_PF: if (nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_PF_NUMBER, attrs->pci_pf.pf)) return -EMSGSIZE; - } else if (devlink_port->attrs.flavour == DEVLINK_PORT_FLAVOUR_PCI_VF) { + break; + case DEVLINK_PORT_FLAVOUR_PCI_VF: if (nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_PF_NUMBER, attrs->pci_vf.pf) || nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_VF_NUMBER, attrs->pci_vf.vf)) return -EMSGSIZE; + break; + case DEVLINK_PORT_FLAVOUR_PHYSICAL: + case DEVLINK_PORT_FLAVOUR_CPU: + case DEVLINK_PORT_FLAVOUR_DSA: + if (nla_put_u32(msg, DEVLINK_ATTR_PORT_NUMBER, + attrs->phys.port_number)) + return -EMSGSIZE; + if (!attrs->split) + return 0; + if (nla_put_u32(msg, DEVLINK_ATTR_PORT_SPLIT_GROUP, + attrs->phys.port_number)) + return -EMSGSIZE; + if (nla_put_u32(msg, DEVLINK_ATTR_PORT_SPLIT_SUBPORT_NUMBER, + attrs->phys.split_subport_number)) + return -EMSGSIZE; + break; + default: + break; } - if (devlink_port->attrs.flavour != DEVLINK_PORT_FLAVOUR_PHYSICAL && - devlink_port->attrs.flavour != DEVLINK_PORT_FLAVOUR_CPU && - devlink_port->attrs.flavour != DEVLINK_PORT_FLAVOUR_DSA) - return 0; - if (nla_put_u32(msg, DEVLINK_ATTR_PORT_NUMBER, - attrs->phys.port_number)) - return -EMSGSIZE; - if (!attrs->split) - return 0; - if (nla_put_u32(msg, DEVLINK_ATTR_PORT_SPLIT_GROUP, - attrs->phys.port_number)) - return -EMSGSIZE; - if (nla_put_u32(msg, DEVLINK_ATTR_PORT_SPLIT_SUBPORT_NUMBER, - attrs->phys.split_subport_number)) - return -EMSGSIZE; return 0; } -- 2.19.2