From patchwork Wed Nov 8 16:45:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ioana Ciornei X-Patchwork-Id: 163106 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:aa0b:0:b0:403:3b70:6f57 with SMTP id k11csp1042679vqo; Wed, 8 Nov 2023 08:47:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IEzWYa0cIQSbRLF7qQ8CbPCfO3vZwBwau+VJf90KUc5DCvyuyeK1fGF/xC1EQkywirFhxN4 X-Received: by 2002:a05:6a20:441f:b0:181:10ee:20ea with SMTP id ce31-20020a056a20441f00b0018110ee20eamr3196329pzb.49.1699462068667; Wed, 08 Nov 2023 08:47:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1699462068; cv=pass; d=google.com; s=arc-20160816; b=vSTLRdFyKYQOoMO54xtp53PFgF4OW2In3HumRptH/RGvVGzzhFTu4dMAw/KRJM/D3O 5mImIKAv94rH9GMsqWTgkq9gQ07MnNHsJguN3oMX1B0AL6rmvktWpW0g0is5qsX81buG hJxc6VBmzH9pSJ6E5/ixq0GLus1yBPtANRKH12RPQFZdDATPowq0i9yqmXNb3ZMQHZ/L LFgrzyY+bnruXZZPuJKpjE5ghl9ye9OW3YN1YtouY/4jC7R7ncdLw1pRrrXq4RMhCEpP BZFRv4hT6JQPUHTq8p/XRiPHoolAbelYR7pbPKxM1rBvsIEXknF+oKh70+MXujRWeMvm V22Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :message-id:date:subject:cc:to:from:dkim-signature; bh=+MawegcjF4UNZnwLD38e1y8oaAgZATjEYyM+2Pd+0dg=; fh=xpHSLiWysv6xAL9n/qDzFAsDtKMzXh4Xk1BuKBnjzfc=; b=lc6egohnChdqp9mMwOALRAGzy8gaiCvIglx/JOosYVwT3c+p9KIn9A2sOhr/GpStNa qtwSrnFEXUf/9ndPCe5jJwGgQ5K773veWqsVg6HpnjZsX1YYC8OhbRCLYQfFWY1OlDr0 Zykvp46AagvEWlOJ0jHDQLy/xgqJcMpn/sPgTZ8a/jsXSNH8Psxn9Yr5ROYGd87+ke7e IMoVwpNw/wqUNqlf9rMNVoPnVPe6xdahR/CKjJ5Vb2dXuYe4xva31LUksXo4TVO3kMh1 hOKV5LJC/1lVasBhrWlnXcN73ORe/qzOka9oRIFVeORDTKSXMTkYEUbDQjOMmirGmuQu 3H+w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=Oa7SS7Eg; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id l196-20020a633ecd000000b0057e21f51ab3si4700463pga.665.2023.11.08.08.47.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Nov 2023 08:47:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=Oa7SS7Eg; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 0056D809E73B; Wed, 8 Nov 2023 08:46:14 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232099AbjKHQqH (ORCPT + 32 others); Wed, 8 Nov 2023 11:46:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229558AbjKHQqC (ORCPT ); Wed, 8 Nov 2023 11:46:02 -0500 Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04on2057.outbound.protection.outlook.com [40.107.6.57]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31DB01FEA for ; Wed, 8 Nov 2023 08:46:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=InXG2wojYqLyrQrPGF67T5baa38fVJpIyz3cHNPi5OC0yf06YG8qMjzDtfnpkLAH2T0HcH0s3tS8pPGG7SgSZeN2QUjcctuJF0fFRpaAMHgT+MGUl10veagNpHYq4t1qKgif9DqV/MBm5UWX9gfYWM6m7WSp+cdk2lawJMzPfaF15MH6DgVT3XcY1krtuivRkzJSEbdfwYQ1YWBGce2MGj0c1jZNGrR1WP7R3SOmxWb1SvKex9EBp4J9hbIvhvJlOtkCHJ7WCZEnmz7lQ3kJmobCBLl/ektSjKHxEixMWVZkJW0hmGOvdJCycIHBhR/G/3saPwZaMg4WI/SYiouLGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=+MawegcjF4UNZnwLD38e1y8oaAgZATjEYyM+2Pd+0dg=; b=GXQpuzCpscmHOLgTuafQF5GDm7S1gbuizL5ondP26+06CrxbxA+Wy1Y3estJaOKiNUJD1xycpX3DLp53Ee2O/+u5HlIVRyfynDPru3O1fdUgcXqqOkaZapOGL5bsyRqMikhUZ7W6wG9DxDmX5MaJ3SjIgJKeLasVLvkbkTMZYmyWBGLJnp6v6lQHyIZZQY1i3HvLZHJL27nsd+R4HVVri3SnTDllpYGl2UAVZ8588QLbuXsUtYukm55q/dULdOa5i1OfxdaGNA4sAHKxIPbfaXK4KPCm/kqtC8fDiN/LJtEB6g8H/21j25nzcinc17+/WOjTggKyS48TmP+wnI0URg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=+MawegcjF4UNZnwLD38e1y8oaAgZATjEYyM+2Pd+0dg=; b=Oa7SS7EgBhpw9a7FMKdRA9dpKPez7iWHhbysfBNknbi9pB8GROGW+lhObC6cz62TaqC1pvJvoFGBTDv27xCNs5qGvH6sZdF1QaNalnrcwN+O5p7xJ5STudDfsnwKHxjV5Dj2rIF/G9Zd3yNFeigSZc5Q3vo7lgO2wjfTtEv2zLc= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from GV1PR04MB9070.eurprd04.prod.outlook.com (2603:10a6:150:21::14) by AS8PR04MB8055.eurprd04.prod.outlook.com (2603:10a6:20b:2a4::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6977.16; Wed, 8 Nov 2023 16:45:57 +0000 Received: from GV1PR04MB9070.eurprd04.prod.outlook.com ([fe80::1290:90d4:98c1:3d35]) by GV1PR04MB9070.eurprd04.prod.outlook.com ([fe80::1290:90d4:98c1:3d35%6]) with mapi id 15.20.6977.018; Wed, 8 Nov 2023 16:45:57 +0000 From: Ioana Ciornei To: gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org Cc: stuyoder@gmail.com, laurentiu.tudor@nxp.com, Ioana Ciornei Subject: [PATCH] bus: fsl-mc: fix double-free on mc_dev Date: Wed, 8 Nov 2023 18:45:46 +0200 Message-Id: <20231108164546.2699574-1-ioana.ciornei@nxp.com> X-Mailer: git-send-email 2.25.1 X-ClientProxiedBy: AS4P195CA0005.EURP195.PROD.OUTLOOK.COM (2603:10a6:20b:5e2::14) To GV1PR04MB9070.eurprd04.prod.outlook.com (2603:10a6:150:21::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: GV1PR04MB9070:EE_|AS8PR04MB8055:EE_ X-MS-Office365-Filtering-Correlation-Id: 87051f5f-ae76-473f-dce0-08dbe07a2e9d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: H/q6mMQKm0SMy++m/MJqX5xtu+uwbGjC2Llnsu8mzMWyWDSwzg1C14WOtH6REStfDk/qUGtqSSpDTABB3yG7UutouNeSMWB2L9EUl3aWMay0qrZ78U9SAha3MqMWkL0XV78K+d257XAaxwSCdGV4uJbacs5tANatXnPvhbIbd3lzc46NSdRuTN+lh/QlJpSHAhIw6FBHduiIpGhvAIBuwtGJ77QbLvhxDnshhj2muONu7qqfBMXYhdvwP3ya+cR9f4uac5i8yaLpCAOKGhLE4aJAcvUiEIRsPW+zA4+cgS1SwPU51DzjaPuEDUie2vpDenvTtvU/DJJfN/K1pahVQ57WXWbWXHtrIzb8vhwIgShP1k3iH1PwK5ENlQzgqQDTMasymaYNb6PdyHLuLu5jw25nKMgIRzHFf5D6NQWXyGUEwiX/jle9FzYhm/OwjCJVBEgJXSzswvSFhx1tyKIDE3w5CY1H6S/R9Xtx+lgp4bvHujBujc8wfzW8xg2CATehea724cuj8m1h20FX3PjulfeX1Yfic1osky3//wmNMc5w8CK5PWd+sNDIkUSzSSkAFAu/wYYeeEa8+wfxE4BE7sYjADiXHaAj5AbB6Mf80NGiq/WQHoj5bD7BwQ9vgfai X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:GV1PR04MB9070.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(376002)(366004)(39860400002)(396003)(346002)(136003)(230922051799003)(230173577357003)(230273577357003)(451199024)(186009)(64100799003)(1800799009)(38100700002)(6666004)(6506007)(83380400001)(6512007)(1076003)(66899024)(2616005)(66556008)(86362001)(41300700001)(8936002)(5660300002)(8676002)(36756003)(4326008)(44832011)(2906002)(66946007)(66476007)(316002)(26005)(478600001)(6486002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: j01mzmHzLf+PKOOuIxerOHw3lZ2c+dL2U+s1EM+o7zV6BVFR2r5VFZjgKp0FsjvBepxvrxAZXnwLmqcIJbdtJm7K2AnXviJyi39vm7VA/w0JN+BvdDkuf9kk1A5uk5xu2EfBAjURPR1FEFuqA3Ziwj0flxSV4R/+1TqCVNCgn35DJn0G8WqRzi05d43YFpHFNuEh/GNUbRfs3k8SBAzea5od/aTRiRO9X1aZAY6GnPB03bu7v/EDwFFiA6+Mu7hZCCfKA3EHoDMvYlkA1d9fERhhq24udFb1F6kb3xQ2WbRA121/TAPXIwdbLF4gsuHKl+xcklzO44p62oE+S0owMR8+E7OBWSuFG10tvkK70ymW1ssv6QR8GRbuHFy6cGsJ+MtutlFINrRsMGx0EPF83q9vGS3zIO+pfbc9s6/xEvCUZccSISn3M+l92pa3WcdK74aFHC/Gt8JcPJ6r5Kv3c2ynRHvcaNCX6Io1zlOHtS3iV+YX/+e85JG/KpwCE//PKQyDp8w50/jsGbZF4hr3OpvsJK40Idh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-Message-Id: 87051f5f-ae76-473f-dce0-08dbe07a2e9d X-MS-Exchange-CrossTenant-AuthSource: GV1PR04MB9070.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Nov 2023 16:45:57.7002 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: diqBWHNNfU4wNs61Bcwj8qOYB9LxFgcrvuk9ba5Wf09tAXu4/r2bVUTJ4Mug/fFTghgeK1UMOe92VhKAKP4vlw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB8055 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 08 Nov 2023 08:46:15 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782015137928571203 X-GMAIL-MSGID: 1782015137928571203 The blamed commit tried to simplify how the deallocations are done but, in the process, introduced a double-free on the mc_dev variable. In case the MC device is a DPRC, a new mc_bus is allocated and the mc_dev variable is just a reference to one of its fields. In this circumstance, on the error path only the mc_bus should be freed. This commit introduces back the following checkpatch warning which is a false-positive. WARNING: kfree(NULL) is safe and this check is probably not required + if (mc_bus) + kfree(mc_bus); Fixes: a042fbed0290 ("staging: fsl-mc: simplify couple of deallocations") Signed-off-by: Ioana Ciornei --- drivers/bus/fsl-mc/fsl-mc-bus.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/bus/fsl-mc/fsl-mc-bus.c b/drivers/bus/fsl-mc/fsl-mc-bus.c index 2f6d5002e43d..b405ee330af1 100644 --- a/drivers/bus/fsl-mc/fsl-mc-bus.c +++ b/drivers/bus/fsl-mc/fsl-mc-bus.c @@ -905,8 +905,10 @@ int fsl_mc_device_add(struct fsl_mc_obj_desc *obj_desc, error_cleanup_dev: kfree(mc_dev->regions); - kfree(mc_bus); - kfree(mc_dev); + if (mc_bus) + kfree(mc_bus); + else + kfree(mc_dev); return error; }