Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp4570899rwb; Tue, 8 Aug 2023 10:16:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHxDCrDHwitLQ4bmgfGqmDtnW7aDB7CGicqBO+YuSrPbXG5cl31a/hpOXsfH2u9Bu1BBHqI X-Received: by 2002:a05:6512:3da7:b0:4fb:744e:17db with SMTP id k39-20020a0565123da700b004fb744e17dbmr123417lfv.1.1691515017516; Tue, 08 Aug 2023 10:16:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691515017; cv=none; d=google.com; s=arc-20160816; b=q+VeQlafvLOyqz1VaDy9f7/XmjlXW/70acgqa2zT7bbEXTZLHzKqqoa0ev0wMNNgQV YcTgMizjVpE8e7PoYJFS/OiPE5bYN2q1EF01CyTLkxDJ+ev52bKx3h9EVrTK9BfHVqxQ sJGKDaqCYOBFjPlWByQOl4rp5+7XaLGeius2G3tbosN+jSrsOwvdBAHM3Ex680O4U/HW fkDqB1zg4pCmkK+FACn91GOzL5omhQFzhl/yJm5R3gz6n5F6Qvrnz7BGvc3q90HazKCC zxhow09Mn0PZChQ4v/uZxV38dVRVeMDxPr9aP7My8j+wJ30hP8frGfzVWKEhJZJADIpZ 0RwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=1aaFBO37dpPCuMBG1yWUb85dTTA1EjCFwxXfWyjK7Qw=; fh=eGhcABT5qpXpiEQQM8X6pP7eRSTx+3Z6L7vgdyrN/OE=; b=QnnjLLncH+V1+uNneTWFJ8MrDoYpy/ZN2o6tVYe4kmXMUTIZQ8ItjFuCZfolYCFC+s MKemo0namOZTylG2PLEyYN73S7n24rE4IH2Chjfcb0HGOlr3SufYgVD2JJ6TafpzSUZK xMwWEYolM+5k47GptslEm6/DHOSfEhpDGiwRj9fIMlK1rTFHNEfTK4gMOnIGGDsP58sI RrQ6Br1XMWCXMG/fczXHe8ho/mictsXBnzapLRHnrxV/l56DIiLRHR57rAOz9Eyy4w2E AdwepWVnk6VzhVY5apBOcQmMUmUQoKP+tenll0IQpXbAdzPCEjxarVWNh5TE1xHU7htf 973A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=y63voWtx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d23-20020a50fb17000000b005232901160dsi5647119edq.485.2023.08.08.10.16.32; Tue, 08 Aug 2023 10:16:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=y63voWtx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234124AbjHHRNE (ORCPT + 99 others); Tue, 8 Aug 2023 13:13:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234279AbjHHRMU (ORCPT ); Tue, 8 Aug 2023 13:12:20 -0400 Received: from mail-oa1-x2d.google.com (mail-oa1-x2d.google.com [IPv6:2001:4860:4864:20::2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 722551BAE6 for ; Tue, 8 Aug 2023 09:05:12 -0700 (PDT) Received: by mail-oa1-x2d.google.com with SMTP id 586e51a60fabf-1bfc2b68090so2505301fac.3 for ; Tue, 08 Aug 2023 09:05:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691510706; x=1692115506; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=1aaFBO37dpPCuMBG1yWUb85dTTA1EjCFwxXfWyjK7Qw=; b=y63voWtx6D7gZlqFm7GmDtTJUHkJeQn+xveYreRAhMpkZB8YxjIzSMztYWtD2pXqy9 QRGNjZtOeHVMsC6cT0kO0V1AAwj26YwM+UAVRGvjZAhCN/XwhfpMKH5IKIQ0QJ8HshDL +MBgRjLuY4Yqa1cDkMsf0Vis92uovto1nAXCwGg4ok+4ia7m6mb+9aop0i3dSNMdnM5X IiWIEK4sIlVtPOynpKRcP8Jp1Ve7jGyu4mOcjquU6bBbdGe452KybS8SaQn1T2nljHDF IP7szJANFzMUoktMqYEC7X71XaPt2l70A5e1dqS4XWJyYryj/RS3aLQLjDGYU04M1WoE XRkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691510706; x=1692115506; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=1aaFBO37dpPCuMBG1yWUb85dTTA1EjCFwxXfWyjK7Qw=; b=IIGTlXyw/oDEI4TKSMxmEWONIyFKnzPCzNmFqTLT69WzCTc7tFLprb3rac3S50Qvf0 8GcJ5QYjOWdtfUY/X75sTROsfNp8PLGFhMUNQ+OFmF0dQj+mk4yAzvvfz196PEM4G/C5 cSriWHBMl6flSR4Aho3uY+ol8SoUVT89zyPWkx/Y2KhS/4gQ3NxsC78YK5Y9Cci15hTy ezi5cWz+PagwBVHeuEAc5U2wiWXtjddxiHLkbqT4qowK0MEgaxQEyeRGi4+m9whM/o2w t8fVjGHCIwzNdpLF+e2MJxQSgw3hrJ6e//KGn6A6y+4H9lDh0V7a2f4ZrDhcu9YZiBfn zTPQ== X-Gm-Message-State: AOJu0YymW2C2HVGGjpEeSkCbHvpb8F6FWHyRMUqxsT1+iF0x5QOHPIDy /ixv62t+b0m+I85SvW6W0H8hF/2GY5B8WRA/mDoDtTj9ugip9zHX9ds= X-Received: by 2002:a25:4ec6:0:b0:d35:9a48:51b0 with SMTP id c189-20020a254ec6000000b00d359a4851b0mr7568564ybb.7.1691485293733; Tue, 08 Aug 2023 02:01:33 -0700 (PDT) MIME-Version: 1.0 References: <20230801052321.1328225-1-harshit.m.mogalapalli@oracle.com> In-Reply-To: <20230801052321.1328225-1-harshit.m.mogalapalli@oracle.com> From: Ulf Hansson Date: Tue, 8 Aug 2023 11:00:57 +0200 Message-ID: Subject: Re: [PATCH next] mmc: sunplus: Fix error handling in spmmc_drv_probe() To: Harshit Mogalapalli Cc: Tony Huang , Li-hao Kuo , Arnd Bergmann , linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org, dan.carpenter@linaro.org, kernel-janitors@vger.kernel.org, error27@gmail.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-0.6 required=5.0 tests=BAYES_00,DATE_IN_PAST_06_12, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 1 Aug 2023 at 07:23, Harshit Mogalapalli wrote: > > There are few issues in spmmc_drv_probe(): > > 1. When mmc allocation fails, goto is a no-op. > 2. When mmc allocation succeeds, the error paths should use goto instead > of direct return. Rather than adding a bunch of new "gotos", how about converting into using devm_mmc_alloc_host()? > 3. platform_get_irq() doesn't return zero, so '<' is sufficient. > > Fix the above issues by adding goto instead of direct return, also > remove NULL check in 'probe_free_host' as we changed the goto to return > when mmc_alloc_host() fails. > > Fixes: 4e268fed8b18 ("mmc: Add mmc driver for Sunplus SP7021") > Reported-by: Dan Carpenter > Closes: https://lore.kernel.org/all/a3829ed3-d827-4b9d-827e-9cc24a3ec3bc@moroto.mountain/ > Signed-off-by: Harshit Mogalapalli Other than the above, this looks good to me! Kind regards Uffe > --- > This is based on static analysis with Smatch. Only compile tested. > --- > drivers/mmc/host/sunplus-mmc.c | 41 ++++++++++++++++++++-------------- > 1 file changed, 24 insertions(+), 17 deletions(-) > > diff --git a/drivers/mmc/host/sunplus-mmc.c b/drivers/mmc/host/sunplus-mmc.c > index a55a87f64d2a..21cd49be08c0 100644 > --- a/drivers/mmc/host/sunplus-mmc.c > +++ b/drivers/mmc/host/sunplus-mmc.c > @@ -864,10 +864,8 @@ static int spmmc_drv_probe(struct platform_device *pdev) > int ret = 0; > > mmc = mmc_alloc_host(sizeof(*host), &pdev->dev); > - if (!mmc) { > - ret = -ENOMEM; > - goto probe_free_host; > - } > + if (!mmc) > + return -ENOMEM; > > host = mmc_priv(mmc); > host->mmc = mmc; > @@ -875,30 +873,40 @@ static int spmmc_drv_probe(struct platform_device *pdev) > host->dma_int_threshold = 1024; > > host->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res); > - if (IS_ERR(host->base)) > - return PTR_ERR(host->base); > + if (IS_ERR(host->base)) { > + ret = PTR_ERR(host->base); > + goto probe_free_host; > + } > > host->clk = devm_clk_get(&pdev->dev, NULL); > - if (IS_ERR(host->clk)) > - return dev_err_probe(&pdev->dev, PTR_ERR(host->clk), "clk get fail\n"); > + if (IS_ERR(host->clk)) { > + ret = dev_err_probe(&pdev->dev, PTR_ERR(host->clk), "clk get fail\n"); > + goto probe_free_host; > + } > > host->rstc = devm_reset_control_get_exclusive(&pdev->dev, NULL); > - if (IS_ERR(host->rstc)) > - return dev_err_probe(&pdev->dev, PTR_ERR(host->rstc), "rst get fail\n"); > + if (IS_ERR(host->rstc)) { > + ret = dev_err_probe(&pdev->dev, PTR_ERR(host->rstc), "rst get fail\n"); > + goto probe_free_host; > + } > > host->irq = platform_get_irq(pdev, 0); > - if (host->irq <= 0) > - return host->irq; > + if (host->irq < 0) { > + ret = host->irq; > + goto probe_free_host; > + } > > ret = devm_request_threaded_irq(&pdev->dev, host->irq, > spmmc_irq, spmmc_func_finish_req, IRQF_SHARED, > NULL, host); > if (ret) > - return ret; > + goto probe_free_host; > > ret = clk_prepare_enable(host->clk); > - if (ret) > - return dev_err_probe(&pdev->dev, ret, "failed to enable clk\n"); > + if (ret) { > + ret = dev_err_probe(&pdev->dev, ret, "failed to enable clk\n"); > + goto probe_free_host; > + } > > ret = mmc_of_parse(mmc); > if (ret) > @@ -940,8 +948,7 @@ static int spmmc_drv_probe(struct platform_device *pdev) > clk_disable_unprepare(host->clk); > > probe_free_host: > - if (mmc) > - mmc_free_host(mmc); > + mmc_free_host(mmc); > > return ret; > } > -- > 2.39.3 >