Received: by 10.213.65.68 with SMTP id h4csp523263imn; Tue, 27 Mar 2018 04:06:37 -0700 (PDT) X-Google-Smtp-Source: AG47ELtgZFQ3iYayJV0A+d7accz7oCWAhuo/XsfSGcw9837OZxNXaVKjMCMEHYfaUvtmU00M6VLI X-Received: by 10.98.41.134 with SMTP id p128mr36451392pfp.120.1522148797726; Tue, 27 Mar 2018 04:06:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522148797; cv=none; d=google.com; s=arc-20160816; b=0GWJoPpLGVfY30ToHWw0fnPCku/71dfDlRUeyVDcxuw0V7ElPpyDm3MVC+hyYZMezn a4YwZsJTUYy2b2gle5HrEwSO9rym/x0o6FDULLZ3x/ZFsrgrIovrPuE9JmOg9gXrdXRE wB6co0rUaS54JokW/BDNhYzxBrDe61+YOPKXI1aoiUtaFkeypOw5vCIGP15xFp40ja9x GKT3WHVHLYS5Da70vTOMAe9ZA6fv4vECrjsvr9kG6YStH1/dGdi/7ucDAcMndMFhOTYV UmAvZg+J/XwK7mkqouihqT6gSTGzsAFSLcgRjw1aqkUzj75uTMO181/V4yioG+XTMnQK vlHA== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=QCB+nB+JgJwV86jRXih4ySrcItQ7cK2ST7HxGvYLcVk=; b=msmvUvvClp42cBN2PWhK03cboc1OA66XGqgH5Rf11uDGccMyDgtXBsrCHJTvvQ0DXA a+NB59y870+j0jvOrGlO+qJK4KNn6723VKK3ngBn5Rd6qXMfZnhjZK7Gk5q86verq4F2 3KE57TcjqUhZjvgUyNXzbjbsf6z/3zLAjn4oi6LtXtsBmDRZQxH7AhQvcbS7AfBGGWfb Lm/DUW6YPLLks8jK7k6kfNzVjmHkfUth8DKzb45KaTSum6oUrmaRDUl/XiCCe8pAaGIh dkybVZ2zfsuMRTAgh/BOFaPz68K3vVuYGqoLzomq2zGcDMvdFNIT6EtgJku13A3xRCu1 FMgA== 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 o12-v6si1000483plg.650.2018.03.27.04.06.23; Tue, 27 Mar 2018 04:06:37 -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 S1751136AbeC0LFU (ORCPT + 99 others); Tue, 27 Mar 2018 07:05:20 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:52898 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750881AbeC0LFT (ORCPT ); Tue, 27 Mar 2018 07:05:19 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0190080D; Tue, 27 Mar 2018 04:05:19 -0700 (PDT) Received: from [10.1.210.88] (e110467-lin.cambridge.arm.com [10.1.210.88]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 0695D3F590; Tue, 27 Mar 2018 04:05:16 -0700 (PDT) Subject: Re: [PATCH v3 2/4] drivers/staging/fsl-mc: Fix DPIO error path issues To: roy.pledge@nxp.com, devel@driverdev.osuosl.org, linux-arm-kernel@lists.infradead.org Cc: ruxandra.radulescu@nxp.com, arnd@arndb.de, gregkh@linuxfoundation.org, horia.geanta@nxp.com, linux-kernel@vger.kernel.org, leoyang.li@nxp.com, stuyoder@gmail.com, catalin.marinas@arm.com, laurentiu.tudor@nxp.com References: <1522091134-24646-1-git-send-email-roy.pledge@nxp.com> <1522091134-24646-3-git-send-email-roy.pledge@nxp.com> From: Robin Murphy Message-ID: <5e91615b-b2b4-4fe3-4d25-1ae56624976b@arm.com> Date: Tue, 27 Mar 2018 12:05:15 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <1522091134-24646-3-git-send-email-roy.pledge@nxp.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Roy, On 26/03/18 20:05, Roy Pledge wrote: > The error path in the dpaa2_dpio_probe() function was not properly > unmapping the QBMan device memory on the error path. This was also > missing from the dpaa2_dpio_release() function. > > Also addresses a memory leak of the device private data structure. > > Signed-off-by: Roy Pledge > --- > drivers/staging/fsl-mc/bus/dpio/dpio-driver.c | 49 +++++++++++++++++++-------- > 1 file changed, 34 insertions(+), 15 deletions(-) > > diff --git a/drivers/staging/fsl-mc/bus/dpio/dpio-driver.c b/drivers/staging/fsl-mc/bus/dpio/dpio-driver.c > index e00f473..e7a0009 100644 > --- a/drivers/staging/fsl-mc/bus/dpio/dpio-driver.c > +++ b/drivers/staging/fsl-mc/bus/dpio/dpio-driver.c > @@ -28,6 +28,7 @@ MODULE_DESCRIPTION("DPIO Driver"); > > struct dpio_priv { > struct dpaa2_io *io; > + struct dpaa2_io_desc desc; > }; > > static irqreturn_t dpio_irq_handler(int irq_num, void *arg) > @@ -85,7 +86,6 @@ static int register_dpio_irq_handlers(struct fsl_mc_device *dpio_dev, int cpu) > static int dpaa2_dpio_probe(struct fsl_mc_device *dpio_dev) > { > struct dpio_attr dpio_attrs; > - struct dpaa2_io_desc desc; > struct dpio_priv *priv; > int err = -ENOMEM; > struct device *dev = &dpio_dev->dev; > @@ -117,7 +117,7 @@ static int dpaa2_dpio_probe(struct fsl_mc_device *dpio_dev) > dev_err(dev, "dpio_get_attributes() failed %d\n", err); > goto err_get_attr; > } > - desc.qman_version = dpio_attrs.qbman_version; > + priv->desc.qman_version = dpio_attrs.qbman_version; > > err = dpio_enable(dpio_dev->mc_io, 0, dpio_dev->mc_handle); > if (err) { > @@ -126,9 +126,9 @@ static int dpaa2_dpio_probe(struct fsl_mc_device *dpio_dev) > } > > /* initialize DPIO descriptor */ > - desc.receives_notifications = dpio_attrs.num_priorities ? 1 : 0; > - desc.has_8prio = dpio_attrs.num_priorities == 8 ? 1 : 0; > - desc.dpio_id = dpio_dev->obj_desc.id; > + priv->desc.receives_notifications = dpio_attrs.num_priorities ? 1 : 0; > + priv->desc.has_8prio = dpio_attrs.num_priorities == 8 ? 1 : 0; > + priv->desc.dpio_id = dpio_dev->obj_desc.id; > > /* get the cpu to use for the affinity hint */ > if (next_cpu == -1) > @@ -139,19 +139,28 @@ static int dpaa2_dpio_probe(struct fsl_mc_device *dpio_dev) > if (!cpu_possible(next_cpu)) { > dev_err(dev, "probe failed. Number of DPIOs exceeds NR_CPUS.\n"); > err = -ERANGE; > - goto err_allocate_irqs; > + goto err_too_many_cpu; > } > - desc.cpu = next_cpu; > + priv->desc.cpu = next_cpu; > > /* > * Set the CENA regs to be the cache inhibited area of the portal to > * avoid coherency issues if a user migrates to another core. > */ > - desc.regs_cena = memremap(dpio_dev->regions[1].start, > - resource_size(&dpio_dev->regions[1]), > - MEMREMAP_WC); > - desc.regs_cinh = ioremap(dpio_dev->regions[1].start, > - resource_size(&dpio_dev->regions[1])); > + priv->desc.regs_cena = memremap(dpio_dev->regions[1].start, > + resource_size(&dpio_dev->regions[1]), > + MEMREMAP_WC); Since you already have some devres-managed resources in this driver, maybe use devm_memremap? (and perhaps convert the existing ioremap too) > + if (!priv->desc.regs_cena) { > + dev_err(dev, "memremap failed\n"); > + goto err_too_many_cpu; > + } > + > + priv->desc.regs_cinh = ioremap(dpio_dev->regions[1].start, > + resource_size(&dpio_dev->regions[1])); > + if (!priv->desc.regs_cinh) { > + dev_err(dev, "ioremap failed\n"); > + goto err_ioremap_failed; > + } > > err = fsl_mc_allocate_irqs(dpio_dev); > if (err) { > @@ -159,11 +168,11 @@ static int dpaa2_dpio_probe(struct fsl_mc_device *dpio_dev) > goto err_allocate_irqs; > } > > - err = register_dpio_irq_handlers(dpio_dev, desc.cpu); > + err = register_dpio_irq_handlers(dpio_dev, priv->desc.cpu); > if (err) > goto err_register_dpio_irq; > > - priv->io = dpaa2_io_create(&desc); > + priv->io = dpaa2_io_create(&priv->desc); > if (!priv->io) { > dev_err(dev, "dpaa2_io_create failed\n"); > goto err_dpaa2_io_create; > @@ -171,7 +180,7 @@ static int dpaa2_dpio_probe(struct fsl_mc_device *dpio_dev) > > dev_info(dev, "probed\n"); > dev_dbg(dev, " receives_notifications = %d\n", > - desc.receives_notifications); > + priv->desc.receives_notifications); > dpio_close(dpio_dev->mc_io, 0, dpio_dev->mc_handle); > fsl_mc_portal_free(dpio_dev->mc_io); > > @@ -182,6 +191,10 @@ static int dpaa2_dpio_probe(struct fsl_mc_device *dpio_dev) > err_register_dpio_irq: > fsl_mc_free_irqs(dpio_dev); > err_allocate_irqs: > + iounmap(priv->desc.regs_cinh); > +err_ioremap_failed: > + memunmap(priv->desc.regs_cena); ...then you wouldn't need to worry about this. > +err_too_many_cpu: > dpio_disable(dpio_dev->mc_io, 0, dpio_dev->mc_handle); > err_get_attr: > dpio_close(dpio_dev->mc_io, 0, dpio_dev->mc_handle); > @@ -189,6 +202,7 @@ static int dpaa2_dpio_probe(struct fsl_mc_device *dpio_dev) > fsl_mc_portal_free(dpio_dev->mc_io); > err_mcportal: > dev_set_drvdata(dev, NULL); > + devm_kfree(dev, priv); The whole point of devm_* is that you don't need to do this - the devres entries are freed automatically by the driver core upon probe failure or driver detach, i.e. priv was never leaking. > err_priv_alloc: > return err; > } > @@ -230,8 +244,13 @@ static int dpaa2_dpio_remove(struct fsl_mc_device *dpio_dev) > > dpio_close(dpio_dev->mc_io, 0, dpio_dev->mc_handle); > > + iounmap(priv->desc.regs_cinh); > + memunmap(priv->desc.regs_cena); > + > fsl_mc_portal_free(dpio_dev->mc_io); > > + devm_kfree(dev, priv); > + > dev_set_drvdata(dev, NULL); Note that clearing drvdata is something else the driver core already does at about the same time as cleaning up devres entries (see __device_release_driver() and the failure path of really_probe(), in drivers/base/dd.c), so this has been similarly superfluous all along. Robin.