Received: by 2002:a05:6358:795:b0:dc:4c66:fc3e with SMTP id n21csp1953481rwj; Sun, 30 Oct 2022 08:56:28 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4DRIETLBPqyy1UxqxKUfwFINmqigqNKK9CRCrdtVzPrIYMBxlJsI0/1y7C1WOl1RZk09DC X-Received: by 2002:a17:906:4c4b:b0:7ad:a197:b58e with SMTP id d11-20020a1709064c4b00b007ada197b58emr8816508ejw.203.1667145388407; Sun, 30 Oct 2022 08:56:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667145388; cv=none; d=google.com; s=arc-20160816; b=lAf//fkGOLKynTGOABw+hA7ldXz5qnBcajfCjYSmox/B5vcwsNxK6Onm5lm6IHUluU odEnnCLbIi05vv3mHUzKpLmu0IIKKcbb/+LI5WuKxwo0zkN3zNPJSjQSxYla3JKrpE/l MrAYQ73S1nqyGc0LxmznA9pPl6w+au2pLOZItmcshZuQ1nUo+zBlG9cFJ1ZMHP5FWlU3 G1L2WyTazh/vETP53iwXSm073VTKnyFYDvz6cf6l01rsdXwQdRMqTsI/52A1z8dI5q5Q /c9ndFKi3ugG6Jer1gbrgQ5FtLbDOv2Pb+M7SRK0JszI8GRvHyVJ8eGjSjHICtRv8inW WjQA== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gx2-20020a1709068a4200b007a1b49ca799si4127047ejc.385.2022.10.30.08.56.03; Sun, 30 Oct 2022 08:56:28 -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 + 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 ); 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 ; 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 To: Maarten Lankhorst , Maxime Ripard , Sumit Semwal , Thomas Zimmermann , =?UTF-8?q?Christian=20K=C3=B6nig?= , David Airlie , Daniel Vetter , noralf@tronnes.org, Dan Carpenter 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: X-Mailing-List: linux-kernel@vger.kernel.org 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 Reviewed-by: Christian König 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 --- 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) { -- 2.37.3