Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3765347pxv; Mon, 19 Jul 2021 08:14:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyrOD7f1LpvIWXBiCww/QLNuPnN+rNl+qha5I+y+7fnBcsHOqyGcYR5VYMpPbnEHW0+CyTn X-Received: by 2002:a17:906:f11:: with SMTP id z17mr28080192eji.385.1626707658239; Mon, 19 Jul 2021 08:14:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626707658; cv=none; d=google.com; s=arc-20160816; b=0Ffa36je2wnrW9s7y0OSe5ZzGR10DrQFNOjeMJSec7U0pHW/rSI9XdWXeBqhpkuIb8 JUjsKS7g0AD6bDg0FTMOwvDz63XEQ6JNhjsJ9n1CUqEybnVEvYOPcwL9m4Yg8JTEE039 SgbK0q1ND98vKHcxT41nGHDH9YhqiEj0UvVJW5rWo3/oGPrJeHTA2VmNbCOccrQEoR+l jQekjBypRmA9xEtqfxMaeo5obtbTgKVe/GSqSFcoXQ24V8/1asoa5XDyjNDcwWOLTwOe 0zmQo3W+Fy5qhhJS0L6MZsM+zB6ggYNhC90IVzCHrY1o5oM68k9qJDe69NHibsMEb1tJ vWGg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=NljVPEte/GGGjxUod2269QKFwcGuOTrzYfj7PE9+Nsg=; b=vxSD/1FtPZVH+Bu1tu6NAe7k7FLLlGoxRFfiW7pwOYi67O4hwnSUaD3VGKC4LU+Pwc 2DN4eFO+eWzB/kCP2eizCPAZAeXXvpQ5tj+7u1Xpui38hlD1QziIEWu6pKlY1udhi5TX o8PL8xrgQgZo3ilPDH0ybq4U1DhsF+eXPmNwUrEOH68xYXuIBxR/Tb1POmS2UvHxZPDU FzeNErea3WXpwMsSIV3Zn5DGksqXsl1wRaQvuCKuavRc+IhhlWMMu4apq+3u/847HSpp xK07qYyQaEqUb66Uz51FUP8khbfVoi90lXkzK5VDtP7itYTj28PZPRE1tO8iav3pSLSG sWaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=sulxdaDt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o18si20379621edq.519.2021.07.19.08.13.55; Mon, 19 Jul 2021 08:14:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=sulxdaDt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245288AbhGSObo (ORCPT + 99 others); Mon, 19 Jul 2021 10:31:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:38112 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243493AbhGSO0C (ORCPT ); Mon, 19 Jul 2021 10:26:02 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id EB3956008E; Mon, 19 Jul 2021 15:06:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626707201; bh=JVLNcAVvJA766fz17y2DwfSvWm1nR3bQ+DMjcfM4Kns=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sulxdaDtpqXJTepzGawoEBcOGPDAcLUg/8wd9VcdDOKs39m/lw5d5g7hC+BpLvu4F qH6Ir9ZPV7kwgA/ywifa001gJXRycz8E+gumcb4SM5H+mhCY1uCMwmAg65xTRfH2vf ODUn1BKbQ8XvJXS0pPTPsFt4Y7VoN/hv76M2ZGbQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hans Verkuil , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 4.9 034/245] media: cobalt: fix race condition in setting HPD Date: Mon, 19 Jul 2021 16:49:36 +0200 Message-Id: <20210719144941.500366594@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210719144940.288257948@linuxfoundation.org> References: <20210719144940.288257948@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Hans Verkuil [ Upstream commit 3d37ef41bed0854805ab9af22c422267510e1344 ] The cobalt_s_bit_sysctrl reads the old register value over PCI, then changes a bit and sets writes the new value to the register. This is used among other things for setting the HPD output pin. But if the HPD is changed for multiple inputs at the same time, then this causes a race condition where a stale value is read. Serialize this function with a mutex. Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/media/pci/cobalt/cobalt-driver.c | 1 + drivers/media/pci/cobalt/cobalt-driver.h | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/media/pci/cobalt/cobalt-driver.c b/drivers/media/pci/cobalt/cobalt-driver.c index 979634000597..17b717a1c7fa 100644 --- a/drivers/media/pci/cobalt/cobalt-driver.c +++ b/drivers/media/pci/cobalt/cobalt-driver.c @@ -689,6 +689,7 @@ static int cobalt_probe(struct pci_dev *pci_dev, return -ENOMEM; cobalt->pci_dev = pci_dev; cobalt->instance = i; + mutex_init(&cobalt->pci_lock); retval = v4l2_device_register(&pci_dev->dev, &cobalt->v4l2_dev); if (retval) { diff --git a/drivers/media/pci/cobalt/cobalt-driver.h b/drivers/media/pci/cobalt/cobalt-driver.h index ed00dc9d9399..8f9454d30b95 100644 --- a/drivers/media/pci/cobalt/cobalt-driver.h +++ b/drivers/media/pci/cobalt/cobalt-driver.h @@ -262,6 +262,8 @@ struct cobalt { int instance; struct pci_dev *pci_dev; struct v4l2_device v4l2_dev; + /* serialize PCI access in cobalt_s_bit_sysctrl() */ + struct mutex pci_lock; void __iomem *bar0, *bar1; @@ -333,10 +335,13 @@ static inline u32 cobalt_g_sysctrl(struct cobalt *cobalt) static inline void cobalt_s_bit_sysctrl(struct cobalt *cobalt, int bit, int val) { - u32 ctrl = cobalt_read_bar1(cobalt, COBALT_SYS_CTRL_BASE); + u32 ctrl; + mutex_lock(&cobalt->pci_lock); + ctrl = cobalt_read_bar1(cobalt, COBALT_SYS_CTRL_BASE); cobalt_write_bar1(cobalt, COBALT_SYS_CTRL_BASE, (ctrl & ~(1UL << bit)) | (val << bit)); + mutex_unlock(&cobalt->pci_lock); } static inline u32 cobalt_g_sysstat(struct cobalt *cobalt) -- 2.30.2