Received: by 10.213.65.68 with SMTP id h4csp651699imn; Tue, 27 Mar 2018 06:23:18 -0700 (PDT) X-Google-Smtp-Source: AG47ELu6GDaST4SUDOY+WE9/WrzUJfG/a0kx9fVJHoB+uGWgZvxrpfZYiAi4FQfBBj/QtpNwy9x0 X-Received: by 10.99.99.65 with SMTP id x62mr17184569pgb.157.1522156997993; Tue, 27 Mar 2018 06:23:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522156997; cv=none; d=google.com; s=arc-20160816; b=zY66s7Z/Kp/CvV3mdUL2dJw4BYrwjnDnqhRKlSedAUjaauGozRRbvMQBHBrn7Sinml yjHYI3UWrKQse7oEF8PSNlnDoLzszWINa5zu+2FzmDxZ8JO5f5hR566UVZDvA5a8Se+3 GBISQ9l7hU7rJU24j6pLKai2AlhT2TIL+qGT12HsrGtpTjT3lIkM7HbeA5KJwz4Xlgpk tcXcMSVh4Gh5UyxsvQuH9M00zePgGrZuPy4lNhugO6oSR9t2oDDWJoQSDReXnxzuLZqE VUHXfbWWL65JuhvWUS7TG4C2Hjnjlsi/06vDxdui+oGRCWQW/aelfw80hlqHapK+h7N4 9QMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=4W2EY/fXJIxw8EiJ/0BeC7TyDz+CpcWhfREbi+C3SOY=; b=o4v3mqKoDypKBPmkRelNNLyAqfxQFcoCZsP8KyOs5mtZRQBOg0NDauGJ3thNf7UpnG y/exZy+7sq5JxZqQjO9h+JSaSnpvfVFa5nyLE59Oo/Wa0cQNeU6+XhvpycdYvq8TOJ75 ipEuwM85RpxnwoL457jT2rsW9ZTBOdFOI1aT9GPyZk0sXppa7/ooVEn91FhhisUTJS6T 4N/IlECtsqrm6X1IeT+j3xJRJM4HezWOBcFzT+LWNeGgoLq9cSXXB0MLuYdp5libvqBh wIC42tW3B8yTKyztcbLDrXUFhu/gOAKreu9/3I2np5d1gG0IEhB0yKnS5Bl06u48n8M1 7qkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector1 header.b=UhL/WGrv; 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=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x65si1013777pfi.65.2018.03.27.06.23.03; Tue, 27 Mar 2018 06:23:17 -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; dkim=pass header.i=@nxp.com header.s=selector1 header.b=UhL/WGrv; 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=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753047AbeC0NT4 (ORCPT + 99 others); Tue, 27 Mar 2018 09:19:56 -0400 Received: from mail-eopbgr30070.outbound.protection.outlook.com ([40.107.3.70]:10272 "EHLO EUR03-AM5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752510AbeC0NTw (ORCPT ); Tue, 27 Mar 2018 09:19:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=4W2EY/fXJIxw8EiJ/0BeC7TyDz+CpcWhfREbi+C3SOY=; b=UhL/WGrvEGSm47gIxfjdPkCGE/3nohu2+UPurVQKHPPcEaPkUAdm5l6pRqFIBA5VnatyVuca1jvHTDyPIQIQwcQutOhm371JvtrEmIAHElZzsAkwlbzgHLN06CkkuOW4t21L28IUasnApt9UNQim3oL/80Dxf0ut17pyFG7wzgI= Received: from DB6PR04MB2999.eurprd04.prod.outlook.com (10.170.213.18) by DB6PR04MB2965.eurprd04.prod.outlook.com (10.170.212.150) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.609.10; Tue, 27 Mar 2018 13:19:48 +0000 Received: from DB6PR04MB2999.eurprd04.prod.outlook.com ([fe80::8476:6431:efeb:2312]) by DB6PR04MB2999.eurprd04.prod.outlook.com ([fe80::8476:6431:efeb:2312%13]) with mapi id 15.20.0609.012; Tue, 27 Mar 2018 13:19:48 +0000 From: Roy Pledge To: Robin Murphy , "devel@driverdev.osuosl.org" , "linux-arm-kernel@lists.infradead.org" CC: Ruxandra Ioana Ciocoi Radulescu , "arnd@arndb.de" , "gregkh@linuxfoundation.org" , =?iso-8859-2?Q?Horia_Geant=E3?= , "linux-kernel@vger.kernel.org" , Leo Li , "stuyoder@gmail.com" , "catalin.marinas@arm.com" , Laurentiu Tudor Subject: Re: [PATCH v3 2/4] drivers/staging/fsl-mc: Fix DPIO error path issues Thread-Topic: [PATCH v3 2/4] drivers/staging/fsl-mc: Fix DPIO error path issues Thread-Index: AQHTxTV7QTuW6ZX0tUiE2xLwpXsWdQ== Date: Tue, 27 Mar 2018 13:19:48 +0000 Message-ID: References: <1522091134-24646-1-git-send-email-roy.pledge@nxp.com> <1522091134-24646-3-git-send-email-roy.pledge@nxp.com> <5e91615b-b2b4-4fe3-4d25-1ae56624976b@arm.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=roy.pledge@nxp.com; x-originating-ip: [192.88.168.1] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DB6PR04MB2965;7:Qrkbz/T8RpXOLJm4nl8AFllt7rC/X5orNDUKaqa+3YwGRxDFoB4cspQKpOQMWAwCqGK1JUru4haSmG+N+OC7WkjkWxIwI8RaFtBLmBHYeFHMBILujeFZpdc0CCYQmndU/mEoSil2dRgZAwrm98x6d4BvDK7yEwP+FmX2okioZGmNBSl6XEt6/cg8wbctKVLshM0VPKlV37mS06GkW2kgax+B218042J6rFEhredgxPVLHFh4VQ1/a+Rt0yd2afuR x-ms-exchange-antispam-srfa-diagnostics: SOS; x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 933baa8a-5420-44a7-5add-08d593e56aad x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020);SRVR:DB6PR04MB2965; x-ms-traffictypediagnostic: DB6PR04MB2965: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(185117386973197)(275809806118684); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(3002001)(10201501046)(3231221)(944501327)(52105095)(93006095)(93001095)(6055026)(6041310)(20161123562045)(20161123558120)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(6072148)(201708071742011);SRVR:DB6PR04MB2965;BCL:0;PCL:0;RULEID:;SRVR:DB6PR04MB2965; x-forefront-prvs: 0624A2429E x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(396003)(376002)(346002)(39380400002)(39860400002)(366004)(199004)(51914003)(189003)(3846002)(186003)(33656002)(26005)(2501003)(3280700002)(2900100001)(106356001)(66066001)(76176011)(6116002)(81156014)(8676002)(8936002)(486005)(486005)(59450400001)(476003)(7736002)(9686003)(6506007)(53546011)(55016002)(2906002)(102836004)(81166006)(5250100002)(229853002)(305945005)(74316002)(25786009)(478600001)(110136005)(4326008)(99286004)(105586002)(5660300001)(14454004)(446003)(53936002)(6246003)(97736004)(86362001)(7696005)(54906003)(3660700001)(68736007)(2201001)(39060400002)(6436002)(316002);DIR:OUT;SFP:1101;SCL:1;SRVR:DB6PR04MB2965;H:DB6PR04MB2999.eurprd04.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; received-spf: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: rI78ycv8ousnTVN8dM/xPsQ+BoRYAhJB4yRXbz8ng/YOkkirqw+oHGH7HEGfhV5CA2UzXxgep4/9qrhDhrV+1jwo2MXvAXSO1K6cQQ6CztocVIuExArhLKf1rogZwGCKaSexURyk216c4Zr9vuBHUTTk8TYlDcwrtnl9Dl2ETXk8sXGYwMNm19LFfzUHFAFi/7IRxpED5a2zZOUo7QtTrOl5LnzBhp4B8qSbRg2DH1h0PAoKk1bkktyE55Q2AqYVp961q1r/NFDhmQMNmlFHjMrl2NqKWT/l610Nu6EphNM4cA6AaGEd8dMnpjqiMpvfrXivwDD1vp68dciesRw4Gg== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-2" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 933baa8a-5420-44a7-5add-08d593e56aad X-MS-Exchange-CrossTenant-originalarrivaltime: 27 Mar 2018 13:19:48.8864 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR04MB2965 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/27/2018 7:05 AM, Robin Murphy wrote:=0A= > Hi Roy,=0A= >=0A= > On 26/03/18 20:05, Roy Pledge wrote:=0A= >> The error path in the dpaa2_dpio_probe() function was not properly=0A= >> unmapping the QBMan device memory on the error path. This was also=0A= >> missing from the dpaa2_dpio_release() function.=0A= >>=0A= >> Also addresses a memory leak of the device private data structure.=0A= >>=0A= >> Signed-off-by: Roy Pledge =0A= >> ---=0A= >> drivers/staging/fsl-mc/bus/dpio/dpio-driver.c | 49 ++++++++++++++++++= +--------=0A= >> 1 file changed, 34 insertions(+), 15 deletions(-)=0A= >>=0A= >> diff --git a/drivers/staging/fsl-mc/bus/dpio/dpio-driver.c b/drivers/sta= ging/fsl-mc/bus/dpio/dpio-driver.c=0A= >> index e00f473..e7a0009 100644=0A= >> --- a/drivers/staging/fsl-mc/bus/dpio/dpio-driver.c=0A= >> +++ b/drivers/staging/fsl-mc/bus/dpio/dpio-driver.c=0A= >> @@ -28,6 +28,7 @@ MODULE_DESCRIPTION("DPIO Driver");=0A= >> =0A= >> struct dpio_priv {=0A= >> struct dpaa2_io *io;=0A= >> + struct dpaa2_io_desc desc;=0A= >> };=0A= >> =0A= >> static irqreturn_t dpio_irq_handler(int irq_num, void *arg)=0A= >> @@ -85,7 +86,6 @@ static int register_dpio_irq_handlers(struct fsl_mc_de= vice *dpio_dev, int cpu)=0A= >> static int dpaa2_dpio_probe(struct fsl_mc_device *dpio_dev)=0A= >> {=0A= >> struct dpio_attr dpio_attrs;=0A= >> - struct dpaa2_io_desc desc;=0A= >> struct dpio_priv *priv;=0A= >> int err =3D -ENOMEM;=0A= >> struct device *dev =3D &dpio_dev->dev;=0A= >> @@ -117,7 +117,7 @@ static int dpaa2_dpio_probe(struct fsl_mc_device *dp= io_dev)=0A= >> dev_err(dev, "dpio_get_attributes() failed %d\n", err);=0A= >> goto err_get_attr;=0A= >> }=0A= >> - desc.qman_version =3D dpio_attrs.qbman_version;=0A= >> + priv->desc.qman_version =3D dpio_attrs.qbman_version;=0A= >> =0A= >> err =3D dpio_enable(dpio_dev->mc_io, 0, dpio_dev->mc_handle);=0A= >> if (err) {=0A= >> @@ -126,9 +126,9 @@ static int dpaa2_dpio_probe(struct fsl_mc_device *dp= io_dev)=0A= >> }=0A= >> =0A= >> /* initialize DPIO descriptor */=0A= >> - desc.receives_notifications =3D dpio_attrs.num_priorities ? 1 : 0;=0A= >> - desc.has_8prio =3D dpio_attrs.num_priorities =3D=3D 8 ? 1 : 0;=0A= >> - desc.dpio_id =3D dpio_dev->obj_desc.id;=0A= >> + priv->desc.receives_notifications =3D dpio_attrs.num_priorities ? 1 : = 0;=0A= >> + priv->desc.has_8prio =3D dpio_attrs.num_priorities =3D=3D 8 ? 1 : 0;= =0A= >> + priv->desc.dpio_id =3D dpio_dev->obj_desc.id;=0A= >> =0A= >> /* get the cpu to use for the affinity hint */=0A= >> if (next_cpu =3D=3D -1)=0A= >> @@ -139,19 +139,28 @@ static int dpaa2_dpio_probe(struct fsl_mc_device *= dpio_dev)=0A= >> if (!cpu_possible(next_cpu)) {=0A= >> dev_err(dev, "probe failed. Number of DPIOs exceeds NR_CPUS.\n");= =0A= >> err =3D -ERANGE;=0A= >> - goto err_allocate_irqs;=0A= >> + goto err_too_many_cpu;=0A= >> }=0A= >> - desc.cpu =3D next_cpu;=0A= >> + priv->desc.cpu =3D next_cpu;=0A= >> =0A= >> /*=0A= >> * Set the CENA regs to be the cache inhibited area of the portal to= =0A= >> * avoid coherency issues if a user migrates to another core.=0A= >> */=0A= >> - desc.regs_cena =3D memremap(dpio_dev->regions[1].start,=0A= >> - resource_size(&dpio_dev->regions[1]),=0A= >> - MEMREMAP_WC);=0A= >> - desc.regs_cinh =3D ioremap(dpio_dev->regions[1].start,=0A= >> - resource_size(&dpio_dev->regions[1]));=0A= >> + priv->desc.regs_cena =3D memremap(dpio_dev->regions[1].start,=0A= >> + resource_size(&dpio_dev->regions[1]),=0A= >> + MEMREMAP_WC);=0A= > Since you already have some devres-managed resources in this driver,=0A= > maybe use devm_memremap? (and perhaps convert the existing ioremap too)= =0A= That would make since - will do.=0A= >=0A= >> + if (!priv->desc.regs_cena) {=0A= >> + dev_err(dev, "memremap failed\n");=0A= >> + goto err_too_many_cpu;=0A= >> + }=0A= >> +=0A= >> + priv->desc.regs_cinh =3D ioremap(dpio_dev->regions[1].start,=0A= >> + resource_size(&dpio_dev->regions[1]));=0A= >> + if (!priv->desc.regs_cinh) {=0A= >> + dev_err(dev, "ioremap failed\n");=0A= >> + goto err_ioremap_failed;=0A= >> + }=0A= >> =0A= >> err =3D fsl_mc_allocate_irqs(dpio_dev);=0A= >> if (err) {=0A= >> @@ -159,11 +168,11 @@ static int dpaa2_dpio_probe(struct fsl_mc_device *= dpio_dev)=0A= >> goto err_allocate_irqs;=0A= >> }=0A= >> =0A= >> - err =3D register_dpio_irq_handlers(dpio_dev, desc.cpu);=0A= >> + err =3D register_dpio_irq_handlers(dpio_dev, priv->desc.cpu);=0A= >> if (err)=0A= >> goto err_register_dpio_irq;=0A= >> =0A= >> - priv->io =3D dpaa2_io_create(&desc);=0A= >> + priv->io =3D dpaa2_io_create(&priv->desc);=0A= >> if (!priv->io) {=0A= >> dev_err(dev, "dpaa2_io_create failed\n");=0A= >> goto err_dpaa2_io_create;=0A= >> @@ -171,7 +180,7 @@ static int dpaa2_dpio_probe(struct fsl_mc_device *dp= io_dev)=0A= >> =0A= >> dev_info(dev, "probed\n");=0A= >> dev_dbg(dev, " receives_notifications =3D %d\n",=0A= >> - desc.receives_notifications);=0A= >> + priv->desc.receives_notifications);=0A= >> dpio_close(dpio_dev->mc_io, 0, dpio_dev->mc_handle);=0A= >> fsl_mc_portal_free(dpio_dev->mc_io);=0A= >> =0A= >> @@ -182,6 +191,10 @@ static int dpaa2_dpio_probe(struct fsl_mc_device *d= pio_dev)=0A= >> err_register_dpio_irq:=0A= >> fsl_mc_free_irqs(dpio_dev);=0A= >> err_allocate_irqs:=0A= >> + iounmap(priv->desc.regs_cinh);=0A= >> +err_ioremap_failed:=0A= >> + memunmap(priv->desc.regs_cena);=0A= > ...then you wouldn't need to worry about this.=0A= >=0A= >> +err_too_many_cpu:=0A= >> dpio_disable(dpio_dev->mc_io, 0, dpio_dev->mc_handle);=0A= >> err_get_attr:=0A= >> dpio_close(dpio_dev->mc_io, 0, dpio_dev->mc_handle);=0A= >> @@ -189,6 +202,7 @@ static int dpaa2_dpio_probe(struct fsl_mc_device *dp= io_dev)=0A= >> fsl_mc_portal_free(dpio_dev->mc_io);=0A= >> err_mcportal:=0A= >> dev_set_drvdata(dev, NULL);=0A= >> + devm_kfree(dev, priv);=0A= > The whole point of devm_* is that you don't need to do this - the devres= =0A= > entries are freed automatically by the driver core upon probe failure or= =0A= > driver detach, i.e. priv was never leaking.=0A= Right - Not sure what I was thinking yesterday. I think I saw the alloc =0A= without free and instinctively=0A= added it.=A0 I will remove this.=0A= >=0A= >> err_priv_alloc:=0A= >> return err;=0A= >> }=0A= >> @@ -230,8 +244,13 @@ static int dpaa2_dpio_remove(struct fsl_mc_device *= dpio_dev)=0A= >> =0A= >> dpio_close(dpio_dev->mc_io, 0, dpio_dev->mc_handle);=0A= >> =0A= >> + iounmap(priv->desc.regs_cinh);=0A= >> + memunmap(priv->desc.regs_cena);=0A= >> +=0A= >> fsl_mc_portal_free(dpio_dev->mc_io);=0A= >> =0A= >> + devm_kfree(dev, priv);=0A= >> +=0A= >> dev_set_drvdata(dev, NULL);=0A= > Note that clearing drvdata is something else the driver core already=0A= > does at about the same time as cleaning up devres entries (see=0A= > __device_release_driver() and the failure path of really_probe(), in=0A= > drivers/base/dd.c), so this has been similarly superfluous all along.=0A= Yes I'll clean this up too.=A0 Thanks for the comments, this will make =0A= things better for sure.=0A= >=0A= > Robin.=0A= >=0A= =0A=