From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 133CFC433EF for ; Mon, 28 Mar 2022 15:09:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244336AbiC1PLL (ORCPT ); Mon, 28 Mar 2022 11:11:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244265AbiC1PKu (ORCPT ); Mon, 28 Mar 2022 11:10:50 -0400 Received: from mail.baikalelectronics.ru (mail.baikalelectronics.com [87.245.175.226]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E0DF25D678; Mon, 28 Mar 2022 08:09:08 -0700 (PDT) Received: from mail.baikalelectronics.ru (unknown [192.168.51.25]) by mail.baikalelectronics.ru (Postfix) with ESMTP id A5BAF1D9D79; Thu, 24 Mar 2022 04:25:34 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.baikalelectronics.ru A5BAF1D9D79 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baikalelectronics.ru; s=mail; t=1648085134; bh=x89tsMKho6WoVTq6R1YvpMJGBDqdDnQvgiGVKdpmT88=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=lWhm1tbMirzpzxmTwcDIWSj/Ofvbjv8L+V09oTbOOx0D7ucDvxBDmnGHObLZw+08C LA77/bp+wewlv2lpTC7P/b13a6p+ZjTXM2BRcJKeyc+7/ye4QQaXmw0BLY+slzotof QwMKj8CDN3Dq15mtyPdEPuw+YjVdWSMMfMhBwVDg= Received: from localhost (192.168.168.10) by mail (192.168.51.25) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Thu, 24 Mar 2022 04:25:34 +0300 From: Serge Semin To: Jingoo Han , Gustavo Pimentel , Bjorn Helgaas , Lorenzo Pieralisi , Rob Herring , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= CC: Serge Semin , Serge Semin , Alexey Malahov , Pavel Parkhomenko , Frank Li , Manivannan Sadhasivam , , Subject: [PATCH 10/12] PCI: dwc-plat: Simplify the probe method return value handling Date: Thu, 24 Mar 2022 04:25:21 +0300 Message-ID: <20220324012524.16784-11-Sergey.Semin@baikalelectronics.ru> In-Reply-To: <20220324012524.16784-1-Sergey.Semin@baikalelectronics.ru> References: <20220324012524.16784-1-Sergey.Semin@baikalelectronics.ru> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: MAIL.baikal.int (192.168.51.25) To mail (192.168.51.25) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The whole switch-case-logic implemented in the DWC PCIe RC/EP probe procedure doesn't seem well thought through. First of all the ret variable is unused in the EP-case and is only partly involved in the RC-case of the switch-case statement, which unnecessary complicates the code. Secondly the probe method will return zero if an unknown mode is detected. That is improbable situation since the OF-device data is initialized only with valid modes, but such code is still wrong at least from maintainability point of view. So let's convert the switch-case part of the probe function to being more coherent. We suggest to use the local ret variable to preserve the status of the case-clauses and return its value from the probe procedure after the work is done. Signed-off-by: Serge Semin --- drivers/pci/controller/dwc/pcie-designware-plat.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/pci/controller/dwc/pcie-designware-plat.c b/drivers/pci/controller/dwc/pcie-designware-plat.c index 0c5de87d3cc6..fea785096261 100644 --- a/drivers/pci/controller/dwc/pcie-designware-plat.c +++ b/drivers/pci/controller/dwc/pcie-designware-plat.c @@ -153,20 +153,21 @@ static int dw_plat_pcie_probe(struct platform_device *pdev) return -ENODEV; ret = dw_plat_add_pcie_port(dw_plat_pcie, pdev); - if (ret < 0) - return ret; break; case DW_PCIE_EP_TYPE: if (!IS_ENABLED(CONFIG_PCIE_DW_PLAT_EP)) return -ENODEV; pci->ep.ops = &pcie_ep_ops; - return dw_pcie_ep_init(&pci->ep); + ret = dw_pcie_ep_init(&pci->ep); + break; default: dev_err(dev, "INVALID device type %d\n", dw_plat_pcie->mode); + ret = -EINVAL; + break; } - return 0; + return ret; } static const struct dw_plat_pcie_of_data dw_plat_pcie_rc_of_data = { -- 2.35.1