Message ID | 20221030154412.8320-2-dmitry.osipenko@collabora.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1851421wru; Sun, 30 Oct 2022 08:46:15 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5BWMy1DqBPwEGM9RgIOSRzMlZwQD46BEYO2aft5whHyBIXyWqr2UT1/D6fZ6cFCixPlbUb X-Received: by 2002:a63:914a:0:b0:46f:7e1c:6584 with SMTP id l71-20020a63914a000000b0046f7e1c6584mr8564870pge.562.1667144775044; Sun, 30 Oct 2022 08:46:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667144775; cv=none; d=google.com; s=arc-20160816; b=sb/rM+qEn5O+ftCasG++CPcD3Em24SKnkmAuU76mpiMQLCsO3Hv36AeK9oB2NqOQUT GzuoGgJgawU/4AZFRXYFbsgoB1FnZowkd9XXPD2hNNIxTVJEtJ7Xujj7+lGjFuIpQEJ2 1YtAIyXNfjYrq2tFCYmcFQhAkZ7aq/ybiQrfFXFHUFQsySZyIfDwGi0/lVv3y6zcnQ5e CBC3lJOtCU+MFPqSXFJem4LuRM2tGXuAREMCCE/QeY7cZ7v4KgXDJoAJRrSoq5kHnEtL FNbbU3e8SNT4GZ6Dngy7249UTjl8OnvbCFAjn4x5biOnqpOF0lWzQWoZjPx/vZv5LMT8 40KA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=iJohQunT65bp1W4F8MRDap9SXeNOcfbklKB9UOjNr4M=; b=UMrVDgUZ0x0Tm9Rnxtx5if0hOCvvbDy/WIXe7/OgoAiwrNAZfoAPbCdAvLJo+Rd5as tY7Zd/nFpLjFEVcSp118gKXkZJd32OZCc3pZXiVLeXB2tOYN9KMH9HcnxWk+UNIJJCvf MlvUzFQK5qlQC423tU4Na/WkGuiTNpm4+Jl5mt1neQridEOq8mHRP4820RMWhTCjUV9l ReTN1H8ES4Qht95jI89qIWZu5wetkC7T6YNIizUnWrB3lqYt4b4BEEnSJVrn2eCgXKcz uRxYKeczSTodxjwC5QkcgQasLHHaowiwloyH3eDPDTuQR6PnK+VBEiF3UE5CmhMgGSWr FKag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=NrgMQ4JJ; 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=NONE dis=NONE) header.from=collabora.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bf6-20020a170902b90600b0017a08290efbsi5052993plb.558.2022.10.30.08.46.02; Sun, 30 Oct 2022 08:46:15 -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=@collabora.com header.s=mail header.b=NrgMQ4JJ; 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=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229827AbiJ3Po6 (ORCPT <rfc822;paulgraves1991@gmail.com> + 99 others); Sun, 30 Oct 2022 11:44:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229717AbiJ3Pox (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sun, 30 Oct 2022 11:44:53 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C85FB1D8 for <linux-kernel@vger.kernel.org>; Sun, 30 Oct 2022 08:44:52 -0700 (PDT) Received: from dimapc.. (unknown [109.252.112.196]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: dmitry.osipenko) by madras.collabora.co.uk (Postfix) with ESMTPSA id 539C7660225F; Sun, 30 Oct 2022 15:44:49 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1667144690; bh=9L1UGeJdnkFYaRnE59XJ8gv48CnIdhLcIsE2uZ/nI0w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NrgMQ4JJcS/wCdnXA8AG/2ltnRc/459pzQVz+tPEzTYMw+l7wUlkqJ3gZn7BQsjRv 9EqSxbTZQnHVfP80TN7xvKFBhY/gqWfvUuzxwqLZJzFlY/fllOOfADR9n2UjVY/Ovw vC2W3JH7CUfTxnn47rZPq8ltpqZkp44vY1VcNNd7WV7ugzd5Wn+KLCw30/TaqhP6IR BTFkOYacsIhlK0YpHKh2lzNCdwaG/NrrN6UBYAaGFaRd+fLrIv1r9kp7pMPoIXazJr hYSBvQpvrwDbcLRpxvHRM31eY6ni/XCZvj9Zmntx78pHz5itR4y+dreooXnjBow/ia PZ8gz0SH1PJQg== From: Dmitry Osipenko <dmitry.osipenko@collabora.com> To: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>, Maxime Ripard <mripard@kernel.org>, Sumit Semwal <sumit.semwal@linaro.org>, Thomas Zimmermann <tzimmermann@suse.de>, =?utf-8?q?Christian_K=C3=B6nig?= <christian.koenig@amd.com>, David Airlie <airlied@gmail.com>, Daniel Vetter <daniel@ffwll.ch>, noralf@tronnes.org, Dan Carpenter <dan.carpenter@oracle.com> Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/2] dma-buf: Make locking consistent in dma_buf_detach() Date: Sun, 30 Oct 2022 18:44:11 +0300 Message-Id: <20221030154412.8320-2-dmitry.osipenko@collabora.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221030154412.8320-1-dmitry.osipenko@collabora.com> References: <20221030154412.8320-1-dmitry.osipenko@collabora.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748127999428221357?= X-GMAIL-MSGID: =?utf-8?q?1748127999428221357?= |
Series |
Fixes for dma-buf locking issues found by Smatch
|
|
Commit Message
Dmitry Osipenko
Oct. 30, 2022, 3:44 p.m. UTC
The dma_buf_detach() locks attach->dmabuf->resv and then unlocks dmabuf->resv, which could be a two different locks from a static code checker perspective. In particular this triggers Smatch to report the "double unlock" error. Make the locking pointers consistent. Reported-by: Dan Carpenter <dan.carpenter@oracle.com> Reviewed-by: Christian König <christian.koenig@amd.com> Link: https://lore.kernel.org/dri-devel/Y1fLfsccW3AS%2Fo+%2F@kili/ Fixes: 809d9c72c2f8 ("dma-buf: Move dma_buf_attach() to dynamic locking specification") Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com> --- drivers/dma-buf/dma-buf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c index c40d72d318fd..13bfd2d09c56 100644 --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c @@ -995,10 +995,10 @@ static void __unmap_dma_buf(struct dma_buf_attachment *attach, */ void dma_buf_detach(struct dma_buf *dmabuf, struct dma_buf_attachment *attach) { - if (WARN_ON(!dmabuf || !attach)) + if (WARN_ON(!dmabuf || !attach || dmabuf != attach->dmabuf)) return; - dma_resv_lock(attach->dmabuf->resv, NULL); + dma_resv_lock(dmabuf->resv, NULL); if (attach->sgt) {