Received: by 2002:a05:6358:795:b0:dc:4c66:fc3e with SMTP id n21csp1761396rwj; Sun, 30 Oct 2022 06:06:49 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7DLND4lMwJZ8/VY5yR/q65mZOvOCK7Bbidp/fsoGlXJ0kA127AyqmPOPzj/2KD0Svj0hX9 X-Received: by 2002:a05:6402:1c88:b0:461:94a0:33df with SMTP id cy8-20020a0564021c8800b0046194a033dfmr8735941edb.0.1667135209410; Sun, 30 Oct 2022 06:06:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1667135209; cv=pass; d=google.com; s=arc-20160816; b=VUjnXN7FEY8KFlherYSlUrsAnI5EUdxqbEZLjJ1dbONbGqvHcWn+6v2x+ulsKMiSzL 7Y+QGrOTVWcZyUnfrdZIrxzyOTRIIbseFxRzCUNneub2AxuwupDJ2BVj1cGOVgCYS5c6 EDmvUt7de7UzgoxeaYaazj9/sF4aJQXPHJ8x8jePloDyWRTTjxB3yfcbT+GW9zQt1cRl lpOEu7qa1rCAdABTCHLTow/BSSe7ooBb5xAZ5tcWXirJVSM7PDwyHV286WPWiKriEueP 21PtQ+A+bEHVi9yqW228s1550tJEGeyLVw7vHFLHtK4cKMy40EX8bIUbVQNMdVBthqNG zSew== 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=svsL4S9jfk3q5oc4G6+CXyigCp88sv9APcA7xWoQvzk=; b=P9pKEVVkoZvxLfyW1TdBXU/d5n/MTFidVzDZ/IMMcFmX6uLqj0taoV+iWI8myCp5W7 Ld1TPKKkgMMHwHP30yG4kO3vcmqOLj+AAtwghkriQhJlPqvG2Dks10AzmJTELd9iIJCc qF4Me+TXLiIPSsQX07I9O7ZeJZkdG4p+ZPhGvbNPoXBm8pxe1GecjqCvm1SoMsJHlrxU QRMG6HHW68cH7XnbhJCNLnlN5yTeZwdTgb0mq6Xcpj6yBJXbdBUoK7eau9VkxVvl/UNJ YhrziJRZaCrMOf2PTNY0cU44DZRJrYDQLdaQL9zSCcPMxbZVrdVz7jJqfV1S49dVDU8n 2YYQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@outlook.com header.s=selector1 header.b=dD6Cda0K; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w9-20020aa7dcc9000000b0045ddb2076casi3947664edu.177.2022.10.30.06.06.23; Sun, 30 Oct 2022 06:06:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@outlook.com header.s=selector1 header.b=dD6Cda0K; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229665AbiJ3LhW (ORCPT + 99 others); Sun, 30 Oct 2022 07:37:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229497AbiJ3LhU (ORCPT ); Sun, 30 Oct 2022 07:37:20 -0400 Received: from JPN01-OS0-obe.outbound.protection.outlook.com (mail-os0jpn01olkn2027.outbound.protection.outlook.com [40.92.98.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6576AE55; Sun, 30 Oct 2022 04:37:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CuTBaEmzOCxjLSJWXzLCCJkrgduIhexB/CjDrjGN4IcDzGO4EQsa6hPlzqXyKIfwDOB4EjY8ALWLvkdIksEzKEU1dEwNhl+mKvm/Oz3uOSbomC+EeXvdweGPmpWnyxOFbAFM25rpQwRnJUZ6yiXJNfg3obVNVX0ESbP/+3F0lssnC8gs8DtprlClQ2vx5ERiER2xWPY9S6fz/EB/4vtAJIm9LrGBcPurOX0+usKII0g4shsBjwj/fUtou9AcTPKTUR4vK/+DVAzzp0ZU/9Chr7Hnx289r9H4oIMYEVSPeyKZNx0tuJRAwMIvjW5khZCOytc7OufNr1DrrS/jic8o/w== 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=svsL4S9jfk3q5oc4G6+CXyigCp88sv9APcA7xWoQvzk=; b=fVIAlrOXPdSef1NDonDUPfCAVVmFTQAC7FeBD0abt2pGz29C6YOJbbuRFR727HaUUEsDrY7J9DJUjayc+dexDpvdhkr7rkOnWkICf+VUr8eUMkR1KOufXaR7UlTnhha3HfxZIiGffveoXcXIJIL9k6MEnDkYADVRma2M1YmIEx+9Y3Zhn65mTnrit3OVBci/xBCDSi9uHtdNv65OJYlpdGMnH+Q3+Fq1o7CWIevlKuU9cMy97U2wkIurcVDofX9MlS/rq5+Xh227BxE9cIGb+kVNjOmF7XFyEZ5vOadBzZxUGsk0CycAt6FtfiGAXWd1cilfqgym667tar9KR5hGxw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=svsL4S9jfk3q5oc4G6+CXyigCp88sv9APcA7xWoQvzk=; b=dD6Cda0KIGFIL+Rpuh60/dgKbd/WmEZ9DF2ULWpJGXK99mUl4HHGEnJKnScSalvcK2bpVXXw96HnePe0i7qIAmHYvg7ivGCAU2on91qH1kVbnBNd6ntIkwfabAKeCOLF4895avFat2jzXLihTiQqgOuHbn7bn6rlL67eTaVQ8lz15TL0oT/ZBsxATdl+c4JXQWL/o3Ln9XiHfHpYbXh2jCWd72XGzTXawGNHcIw/SBRkBDMFJimM2jrKsg7Z3JWQIOeJ/bx6kCRMU3RU9AGhaQfDY2nAYSC+FqF3dp5YOyaEaytDzHPDqC4st29IZPilKZYkjW33XmaqN532BXUZBQ== Received: from TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:152::9) by OS3P286MB2709.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:1fc::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5769.16; Sun, 30 Oct 2022 11:37:12 +0000 Received: from TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM ([fe80::c90e:cbf3:c23d:43a5]) by TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM ([fe80::c90e:cbf3:c23d:43a5%7]) with mapi id 15.20.5769.018; Sun, 30 Oct 2022 11:37:12 +0000 From: Dawei Li To: sumit.semwal@linaro.org, christian.koenig@amd.com Cc: benjamin.gaignard@collabora.com, lmark@codeaurora.org, labbott@redhat.com, Brian.Starkey@arm.com, jstultz@google.com, afd@ti.com, sspatil@android.com, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org, Dawei Li Subject: [PATCH] dma-buf: fix racing conflict of dma_heap_add() Date: Sun, 30 Oct 2022 19:37:00 +0800 Message-ID: X-Mailer: git-send-email 2.25.1 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-TMN: [Um6xlQbCyYoT19WyxqearVE+xI9G5zJia2KmZRKIW1k=] X-ClientProxiedBy: TY1PR01CA0184.jpnprd01.prod.outlook.com (2603:1096:403::14) To TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:152::9) X-Microsoft-Original-Message-ID: <20221030113700.3300-1-set_pte_at@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TYCP286MB2323:EE_|OS3P286MB2709:EE_ X-MS-Office365-Filtering-Correlation-Id: 4cdf1d64-4620-4054-bfbc-08daba6b15da X-MS-Exchange-SLBlob-MailProps: 70qbaZjg4mv1OqsmyvwVkO5pclI01FVpovJWLvgsAQ8XASbU4UOFaqFZL/PS2XbnOslcIt6Wz0uOSrOC9MGcWkJXC3bdrn+h519oQNbJEaL8MJvXBIOdsh89jAQfeDMMTP5LypWXzKXsx8nlrc/aMGMQfzEhe+Ws6WwLSAnvj0I7dCqywraaYzSvSCw7SxCd733Zr9JOCQPxgKAUs/6Rksg2iItWHErYYFlyGYezzUOKi/inmm0bxARf2o2Rz1/E47PEK37FbCpY8CJBfgqDPLx4nEfEhT6s3t7MW5sfqrS9qJc3wlFMRsDElf355N0PuFG0d/lsg1dFBeTDwXYGm1BcjdCgdBdkmWpgtd0EMxd5T2EXL6/FRB6dfaubfQXoceHEbgRoklqTeOddYl/42zOjEyROZcfZZN254tsOJB7MTyH/XHU0eOTZ1I0d92ANjy92T/UapdclR/SN6T/PgYMRv0XFcB7YQg3Ss/PF6yWMioH/qaCcJrBHqa3nSovpVSlk7Frm8qyvrI7/A+Ip0rSY2JKSJEh4NvycrQVplHqVj8S+/JCMacYgvCJpZSWUp5S3N8UYQuLXjvau2u+gQ5oS1PwXUXEnjdTAjpAkpt/8yPjvh1dQFO+SkAgDDulz9f29ZCremVJX4ghP/k0aF41fQin0jP/tSku/H0mD4TnUKxi8RwwrmnZYdmmf65bPaAFRvfkba30wCx2OhTJvrMcQkN45LyatOaO55nrsaF7w8Xqmb7DOfg== X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: npwPx69ixe1sxoMNDYfYUA7fZtfrSfxK62GQHUd5RopMghybxACdtqy/AS5vsojqtR0RiXMKW4dSNVaRf+QcmHCM3b/acDmxYIdCb9bOhFSyRGRVMJRiCDTdPvBzONPFtKmjE72Q0+PvofWBbuq7+D7o4Fxu1TXsqsWU8ER158ucWBZqR8njxcJOssosbuX7eqZYGKaRXob+PjlSJSFVEvMimh4xh2tPuCblIE1JVqO2mWEg6wkJqH+iOJFJUKbe5/5UFVDFVYrntdhnS1Vj9AXcp2bLLmzjQDWs6jYtO/dTukU67NJkGKPKNZAs30FTW6DYpsn2/wAPuGMHYPWJ1tPOvJwBPq0ZCO5puoKtSzYuPm8EWzZJu/2/plLVh6kwZY5BvRYav9jAaP+8IPZ7cqdvNbm0W6WYCCePbND3wVb7NOCTfSfedOJumn619c8Q9A+0/PfUDY8iKEPTjXp6dc+5nvCkwg/pgEzDY/ZePJNoEPTiHkoJMbtZhwOVnhCl848M2HT6Iow+8C+dUFgB7MiYbeScJHPidJbG8vVZE1YLfcz8ZcNsfaTCiUJrOcfavi/UFVSp7ti4XhDdgzsaa3v1O/uEh3GBo3wr55cqThARCOXpSdAO3mlm5korTby3aHo1zzf/QZfHchiTM2O/N3019oO7Ql+FHV8US4L8xutCFi9hsintRYFe6LxYXSAk X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?uGvSjUt3TnD/upyIr0DnlNx3FB7ZyABhagnJeFMh71SgKZpSUggnwRJhkfPq?= =?us-ascii?Q?3Ax+VfCKY96Rr/rXjby1YpcrReqtb+VkQ/rQHoTSSrQKGdFfRSp9usQCI/1f?= =?us-ascii?Q?456r4J9uD1yrVWmVK7vlKjgp4XgeZ8PWDoTEVMMwZuo+xAC4uSS0LsW/ICke?= =?us-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10uUaGWq4Cm1LMALyeVc?= =?us-ascii?Q?J0Ex7n9S2XXXLdis0NI48In9Dhb+qC+gS0/JOoz7WeRq56KLw0uI/TsXEuPt?= =?us-ascii?Q?VtUlkT3ZFPYMIBqNwLA0q84nfjeME6v4d9DrfF8GTyWUuvQHtc/7G9Tk0iR0?= =?us-ascii?Q?gMFN/SivhOHCsTQlKLtqGpPl0anElXMf+ZurA70b3sqwhXjs0LVB+1EX3lRn?= =?us-ascii?Q?Tuktl+UcbfH6YqawdQnV61zricy62yny3tSL+39j8A=3D=3D?= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4cdf1d64-4620-4054-bfbc-08daba6b15da X-MS-Exchange-CrossTenant-AuthSource: TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Oct 2022 11:37:12.0082 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: OS3P286MB2709 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Racing conflict could be: task A task B list_for_each_entry strcmp(h->name)) list_for_each_entry strcmp(h->name) kzalloc kzalloc ...... ..... device_create device_create list_add list_add The root cause is that task B has no idea about the fact someone else(A) has inserted heap with same name when it calls list_add, so a potential collision occurs. Fixes: c02a81fba74f ("dma-buf: Add dma-buf heaps framework") base-commit: 447fb14bf07905b880c9ed1ea92c53d6dd0649d7 Signed-off-by: Dawei Li --- drivers/dma-buf/dma-heap.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/dma-buf/dma-heap.c b/drivers/dma-buf/dma-heap.c index 8f5848aa144f..ff44c2777b04 100644 --- a/drivers/dma-buf/dma-heap.c +++ b/drivers/dma-buf/dma-heap.c @@ -243,11 +243,12 @@ struct dma_heap *dma_heap_add(const struct dma_heap_export_info *exp_info) return ERR_PTR(-EINVAL); } } - mutex_unlock(&heap_list_lock); heap = kzalloc(sizeof(*heap), GFP_KERNEL); - if (!heap) + if (!heap) { + mutex_unlock(&heap_list_lock); return ERR_PTR(-ENOMEM); + } heap->name = exp_info->name; heap->ops = exp_info->ops; @@ -284,7 +285,6 @@ struct dma_heap *dma_heap_add(const struct dma_heap_export_info *exp_info) goto err2; } /* Add heap to the list */ - mutex_lock(&heap_list_lock); list_add(&heap->list, &heap_list); mutex_unlock(&heap_list_lock); @@ -296,6 +296,7 @@ struct dma_heap *dma_heap_add(const struct dma_heap_export_info *exp_info) xa_erase(&dma_heap_minors, minor); err0: kfree(heap); + mutex_unlock(&heap_list_lock); return err_ret; } -- 2.25.1