From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752914AbbC0VIG (ORCPT ); Fri, 27 Mar 2015 17:08:06 -0400 Received: from mail-bn1on0135.outbound.protection.outlook.com ([157.56.110.135]:48341 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752737AbbC0VHr (ORCPT ); Fri, 27 Mar 2015 17:07:47 -0400 From: "J. German Rivera" To: , , , CC: , , , , , , , , , "J. German Rivera" Subject: [PATCH 4/6] staging: fsl-mc: Fix crash in fsl_mc_device_remove() Date: Fri, 27 Mar 2015 16:01:07 -0500 Message-ID: <1427490069-3142-5-git-send-email-German.Rivera@freescale.com> X-Mailer: git-send-email 2.3.3 In-Reply-To: <1427490069-3142-1-git-send-email-German.Rivera@freescale.com> References: <1427490069-3142-1-git-send-email-German.Rivera@freescale.com> X-EOPAttributedMessage: 0 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=German.Rivera@freescale.com; freescale.mail.onmicrosoft.com; dkim=none (message not signed) header.d=none; X-Forefront-Antispam-Report: CIP:192.88.168.50;CTRY:US;IPV:NLI;EFV:NLI;BMV:1;SFV:NSPM;SFS:(10019020)(6009001)(339900001)(189002)(199003)(46102003)(36756003)(105606002)(86362001)(48376002)(19580395003)(50466002)(85426001)(19580405001)(106466001)(77096005)(76176999)(50986999)(2950100001)(77156002)(87936001)(92566002)(50226001)(2201001)(229853001)(47776003)(62966003);DIR:OUT;SFP:1102;SCL:1;SRVR:DM2PR03MB509;H:tx30smr01.am.freescale.net;FPR:;SPF:Fail;MLV:sfv;MX:1;A:1;LANG:en; MIME-Version: 1.0 Content-Type: text/plain X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DM2PR03MB509; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(5002010)(5005006);SRVR:DM2PR03MB509;BCL:0;PCL:0;RULEID:;SRVR:DM2PR03MB509; X-Forefront-PRVS: 0528942FD8 X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Mar 2015 21:07:42.1399 (UTC) X-MS-Exchange-CrossTenant-Id: 710a03f5-10f6-4d38-9ff4-a80b81da590d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=710a03f5-10f6-4d38-9ff4-a80b81da590d;Ip=[192.88.168.50];Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR03MB509 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Only call fsl_mc_io_destroy() if the DPRC being removed actually had an mc_io object associated with. Child DPRCs that have not been bound to the DPRC driver or the VFIO driver will not have an mc_io associated with them. Signed-off-by: J. German Rivera --- drivers/staging/fsl-mc/bus/dprc-driver.c | 9 ++------- drivers/staging/fsl-mc/bus/mc-bus.c | 9 +++++---- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/drivers/staging/fsl-mc/bus/dprc-driver.c b/drivers/staging/fsl-mc/bus/dprc-driver.c index 9568eea..35c06cf 100644 --- a/drivers/staging/fsl-mc/bus/dprc-driver.c +++ b/drivers/staging/fsl-mc/bus/dprc-driver.c @@ -167,7 +167,6 @@ static void dprc_add_new_devices(struct fsl_mc_device *mc_bus_dev, for (i = 0; i < num_child_objects_in_mc; i++) { struct fsl_mc_device *child_dev; - struct fsl_mc_io *mc_io = NULL; struct dprc_obj_desc *obj_desc = &obj_desc_array[i]; if (strlen(obj_desc->type) == 0) @@ -182,14 +181,10 @@ static void dprc_add_new_devices(struct fsl_mc_device *mc_bus_dev, continue; } - error = fsl_mc_device_add(obj_desc, mc_io, &mc_bus_dev->dev, + error = fsl_mc_device_add(obj_desc, NULL, &mc_bus_dev->dev, &child_dev); - if (error < 0) { - if (mc_io) - fsl_destroy_mc_io(mc_io); - + if (error < 0) continue; - } } } diff --git a/drivers/staging/fsl-mc/bus/mc-bus.c b/drivers/staging/fsl-mc/bus/mc-bus.c index de15fa9..d943d99 100644 --- a/drivers/staging/fsl-mc/bus/mc-bus.c +++ b/drivers/staging/fsl-mc/bus/mc-bus.c @@ -444,15 +444,16 @@ void fsl_mc_device_remove(struct fsl_mc_device *mc_dev) put_device(&mc_dev->dev); if (strcmp(mc_dev->obj_desc.type, "dprc") == 0) { - struct fsl_mc_io *mc_io = mc_dev->mc_io; - mc_bus = to_fsl_mc_bus(mc_dev); - fsl_destroy_mc_io(mc_io); + if (mc_dev->mc_io) { + fsl_destroy_mc_io(mc_dev->mc_io); + mc_dev->mc_io = NULL; + } + if (&mc_dev->dev == fsl_mc_bus_type.dev_root) fsl_mc_bus_type.dev_root = NULL; } - mc_dev->mc_io = NULL; if (mc_bus) devm_kfree(mc_dev->dev.parent, mc_bus); else -- 2.3.3