Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp736126ybi; Fri, 14 Jun 2019 02:28:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqzceeHO4VTlfsaibTXPqWNpjziBmQtr4VRHb9r06QB7ufaOqp5MRf/isX/XRmu7bp3zHlQh X-Received: by 2002:a63:5158:: with SMTP id r24mr34581809pgl.79.1560504499675; Fri, 14 Jun 2019 02:28:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560504499; cv=none; d=google.com; s=arc-20160816; b=P6IU+3exh1Ihb3i4QEsdN7VXx/8ynbJziGwH4GPQu6Z8/9XeZbYn9OoeU2aQHSIKRg iTQ1WX5DDIGrO9VEtawaGp5Xdw9JEX0QrHkDVWLfwFpO/TR207avmeisMzr8cNbgbQ01 qVnwXiZQkakJYURdfUI4Ipj6XuTQpOM6goJN8ifrwIaQEzrsnhw3adK0Qc7WD0ju7zVt aZnHXqZrufodWKZKYgD4CladTGYgCyoQ9lurGStffr0/79lc1XaKgzf9NQS26a2l+P+V eiW1MI5HUnnDqrQo3h9qzU8zn4eu0iWnhJEdGEE57Y2kldINzYAmtDkvIR9q6uF9FW03 D9vw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date; bh=8dKDuzUXC+JERMGvQmu4FkJpw6XKdbXQgdBl4pYmyHQ=; b=iXFbzjvGuytp9q6xueZD+tcepCfFhHW/iEZHva49TVqTC6tD6te2oJzzHrODAT2bEz Pg4S/tUGPNKvO6btDzPideUSiPy9YeP20pfNXb+VI1TrsxfKZ+iCUK2SbwVxvUwBqdzi HDZWaWFwGeFt19vjO3ARGFSuqDCbiCBkic6xKdgky0rwNs7A7vKKUamEgNu1wZgQW020 Gm/2XsSXkMKtaGbHW6ALcGEygZRPrjYDL77/TjM8az8pWIUuBbNMLrGARJekNWncr0GS oI0P/nzSdrepgdh5IyiDdyAf7EApgJL0hizR+PJJJBxl/huqlamgiDPx8x1j66jIRq7Y EX0Q== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c14si2041703pgi.96.2019.06.14.02.28.03; Fri, 14 Jun 2019 02:28:19 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727004AbfFNJ1v (ORCPT + 99 others); Fri, 14 Jun 2019 05:27:51 -0400 Received: from mail3-relais-sop.national.inria.fr ([192.134.164.104]:63450 "EHLO mail3-relais-sop.national.inria.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726479AbfFNJ1v (ORCPT ); Fri, 14 Jun 2019 05:27:51 -0400 X-IronPort-AV: E=Sophos;i="5.63,372,1557180000"; d="scan'208";a="309239293" Received: from unknown (HELO hadrien.local) ([163.173.90.224]) by mail3-relais-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Jun 2019 11:27:47 +0200 Date: Fri, 14 Jun 2019 11:27:47 +0200 (CEST) From: Julia Lawall X-X-Sender: jll@hadrien To: Markus Elfring cc: Enrico Weigelt , Greg Kroah-Hartman , "Rafael J. Wysocki" , Michal Marek , Nicolas Palix , Linus Walleij , kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski , Andy Shevchenko , cocci@systeme.lip6.fr Subject: Re: [Cocci] [PATCH] drivers: Inline code in devm_platform_ioremap_resource() from two functions In-Reply-To: <032e347f-e575-c89c-fa62-473d52232735@web.de> Message-ID: References: <20190406061112.31620-1-himanshujha199640@gmail.com> <7b4fe770-dadd-80ba-2ba4-0f2bc90984ef@web.de> <032e347f-e575-c89c-fa62-473d52232735@web.de> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 14 Jun 2019, Markus Elfring wrote: > From: Markus Elfring > Date: Fri, 14 Jun 2019 11:05:33 +0200 > > Two function calls were combined in this function implementation. > Inline corresponding code so that extra error checks can be avoided here. I don't see any point to this at all. By inlining the code, you have created a clone, which will introduce extra work to maintain in the future. julia > > Signed-off-by: Markus Elfring > --- > drivers/base/platform.c | 39 ++++++++++++++++++++++++++++++++++----- > 1 file changed, 34 insertions(+), 5 deletions(-) > > diff --git a/drivers/base/platform.c b/drivers/base/platform.c > index 4d1729853d1a..baadca72f949 100644 > --- a/drivers/base/platform.c > +++ b/drivers/base/platform.c > @@ -80,8 +80,8 @@ struct resource *platform_get_resource(struct platform_device *dev, > EXPORT_SYMBOL_GPL(platform_get_resource); > > /** > - * devm_platform_ioremap_resource - call devm_ioremap_resource() for a platform > - * device > + * devm_platform_ioremap_resource > + * Achieve devm_ioremap_resource() functionality for a platform device > * > * @pdev: platform device to use both for memory resource lookup as well as > * resource management > @@ -91,10 +91,39 @@ EXPORT_SYMBOL_GPL(platform_get_resource); > void __iomem *devm_platform_ioremap_resource(struct platform_device *pdev, > unsigned int index) > { > - struct resource *res; > + u32 i; > > - res = platform_get_resource(pdev, IORESOURCE_MEM, index); > - return devm_ioremap_resource(&pdev->dev, res); > + for (i = 0; i < pdev->num_resources; i++) { > + struct resource *res = &pdev->resource[i]; > + > + if (resource_type(res) == IORESOURCE_MEM && index-- == 0) { > + struct device *dev = &pdev->dev; > + resource_size_t size = resource_size(res); > + void __iomem *dest; > + > + if (!devm_request_mem_region(dev, > + res->start, > + size, > + dev_name(dev))) { > + dev_err(dev, > + "can't request region for resource %pR\n", > + res); > + return IOMEM_ERR_PTR(-EBUSY); > + } > + > + dest = devm_ioremap(dev, res->start, size); > + if (!dest) { > + dev_err(dev, > + "ioremap failed for resource %pR\n", > + res); > + devm_release_mem_region(dev, res->start, size); > + dest = IOMEM_ERR_PTR(-ENOMEM); > + } > + > + return dest; > + } > + } > + return IOMEM_ERR_PTR(-EINVAL); > } > EXPORT_SYMBOL_GPL(devm_platform_ioremap_resource); > #endif /* CONFIG_HAS_IOMEM */ > -- > 2.22.0 > > _______________________________________________ > Cocci mailing list > Cocci@systeme.lip6.fr > https://systeme.lip6.fr/mailman/listinfo/cocci >