From patchwork Thu Apr 8 07:40:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mauro Carvalho Chehab X-Patchwork-Id: 417792 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C2DA7C433B4 for ; Thu, 8 Apr 2021 07:40:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 812FA6115B for ; Thu, 8 Apr 2021 07:40:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229623AbhDHHkV (ORCPT ); Thu, 8 Apr 2021 03:40:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:53596 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229517AbhDHHkT (ORCPT ); Thu, 8 Apr 2021 03:40:19 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 537676113A; Thu, 8 Apr 2021 07:40:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1617867608; bh=wapQTnSFiV1ZtG9q0iplLDk1SJVcJTFJRTo/iVI10D8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jY6qUnRldNElEAzowUqgaGbn3nss6H995XeWKFHfCivqJw5fC+mo3agAPVF6BzVTU esWgX7Vlx/edCn0aXgEITCTtDQYhVRo/xV927aCJcWB7JqN3kOof8zU/3wajQR2FM1 9b9IchiOQV9AZJ4LTUxi1vKWKPLRKzv9ZW5mT/INyOrWxtGYfOdG9I/QObX7Oij3lL AVxDbg9jB0GO/dWsNtSh3VBnrp/yTB44CGhOR9k4Xipux2QLC4EGWBuhSDjMM78dQb l8cWsme+uXUxK/W48W3NZQh0ySry6PYTyxBXIimZPgSNLK4ufND+bWKs+iECzTgm8U daEIo7482tFgA== Received: by mail.kernel.org with local (Exim 4.94) (envelope-from ) id 1lUPGn-000jTz-VS; Thu, 08 Apr 2021 09:40:05 +0200 From: Mauro Carvalho Chehab Cc: linuxarm@huawei.com, mauro.chehab@huawei.com, Mauro Carvalho Chehab , =?utf-8?q?Niklas_S=C3=B6derlund?= , Jacopo Mondi , Kieran Bingham , Laurent Pinchart , Mauro Carvalho Chehab , linux-kernel@vger.kernel.org, linux-media@vger.kernel.org Subject: [PATCH 2/3] media: rdacm21: describe better a truncation Date: Thu, 8 Apr 2021 09:40:03 +0200 Message-Id: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Sender: Mauro Carvalho Chehab To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org As warned by sparse: drivers/media/i2c/rdacm21.c:348:62: warning: cast truncates bits from constant value (300a becomes a) the intention of the code is to get just the lowest 8 bits. So, instead of using a typecast, use a bit and logic. Signed-off-by: Mauro Carvalho Chehab --- drivers/media/i2c/rdacm21.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/media/i2c/rdacm21.c b/drivers/media/i2c/rdacm21.c index dcc21515e5a4..179d107f494c 100644 --- a/drivers/media/i2c/rdacm21.c +++ b/drivers/media/i2c/rdacm21.c @@ -345,7 +345,7 @@ static int ov10640_initialize(struct rdacm21_device *dev) /* Read OV10640 ID to test communications. */ ov490_write_reg(dev, OV490_SCCB_SLAVE0_DIR, OV490_SCCB_SLAVE_READ); ov490_write_reg(dev, OV490_SCCB_SLAVE0_ADDR_HIGH, OV10640_CHIP_ID >> 8); - ov490_write_reg(dev, OV490_SCCB_SLAVE0_ADDR_LOW, (u8)OV10640_CHIP_ID); + ov490_write_reg(dev, OV490_SCCB_SLAVE0_ADDR_LOW, OV10640_CHIP_ID & 0xff); /* Trigger SCCB slave transaction and give it some time to complete. */ ov490_write_reg(dev, OV490_HOST_CMD, OV490_HOST_CMD_TRIGGER); From patchwork Thu Apr 8 07:40:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mauro Carvalho Chehab X-Patchwork-Id: 417791 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3959FC433B4 for ; Thu, 8 Apr 2021 07:40:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 119EF61157 for ; Thu, 8 Apr 2021 07:40:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230302AbhDHHk0 (ORCPT ); Thu, 8 Apr 2021 03:40:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:53600 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229566AbhDHHkT (ORCPT ); Thu, 8 Apr 2021 03:40:19 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 589A461155; Thu, 8 Apr 2021 07:40:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1617867608; bh=K40uSsuCJ5wtmzix6+AZWZGkHxgr6P49paxJVnSNP8E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LzSMqZbJsrAmXiB+7CKXvwOFpqF4CVz6an0EEj36Ih0xR2jiYTaojdaU+/Aue4MmP ZDhIH3CV2U1lx1GxNCdfNDq5xHeSydqeZFF9gHACf6D2/NBZZoTN4lL2HQHursLwzF 2gAM3GR38yiTcJscrsXzIZK0FEWPWz55pqsnP86depi/5jL1/pLoAZCqo8ZrQJVDBK 4EmKNozUE8+KX1kCEwvKDmiiFHJCPht0VUUwzPZQo7A2+tIXf6zL3RLxMnMHTow+Pl W4zOBo0XwwwE9amJ5udA9p/+Ooen+obokCNtdypjlFscmm+gQ0XIxJ406FGj5dHIrU XYziezcGuPivQ== Received: by mail.kernel.org with local (Exim 4.94) (envelope-from ) id 1lUPGo-000jU2-0N; Thu, 08 Apr 2021 09:40:06 +0200 From: Mauro Carvalho Chehab Cc: linuxarm@huawei.com, mauro.chehab@huawei.com, Mauro Carvalho Chehab , Andy Gross , Bjorn Andersson , Mauro Carvalho Chehab , Stanimir Varbanov , linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org Subject: [PATCH 3/3] media: venus: don't de-reference NULL pointers at IRQ time Date: Thu, 8 Apr 2021 09:40:04 +0200 Message-Id: <73570a5dfe7b3411d256367d4a2a02169aa9b900.1617867599.git.mchehab+huawei@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Sender: Mauro Carvalho Chehab To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Smatch is warning that: drivers/media/platform/qcom/venus/hfi_venus.c:1100 venus_isr() warn: variable dereferenced before check 'hdev' (see line 1097) The logic basically does: hdev = to_hfi_priv(core); with is translated to: hdev = core->priv; If the IRQ code can receive a NULL pointer for hdev, there's a bug there, as it will first try to de-reference the pointer, and then check if it is null. After looking at the code, it seems that this indeed can happen: Basically, the venus IRQ thread is started with: devm_request_threaded_irq() So, it will only be freed after the driver unbinds. In order to prevent the IRQ code to work with freed data, the logic at venus_hfi_destroy() sets core->priv to NULL, which would make the IRQ code to ignore any pending IRQs. There is, however a race condition, as core->priv is set to NULL only after being freed. So, we need also to move the core->priv = NULL to happen earlier. Signed-off-by: Mauro Carvalho Chehab Acked-by: Stanimir Varbanov --- drivers/media/platform/qcom/venus/hfi_venus.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/media/platform/qcom/venus/hfi_venus.c b/drivers/media/platform/qcom/venus/hfi_venus.c index cebb20cf371f..ce98c523b3c6 100644 --- a/drivers/media/platform/qcom/venus/hfi_venus.c +++ b/drivers/media/platform/qcom/venus/hfi_venus.c @@ -1094,12 +1094,15 @@ static irqreturn_t venus_isr(struct venus_core *core) { struct venus_hfi_device *hdev = to_hfi_priv(core); u32 status; - void __iomem *cpu_cs_base = hdev->core->cpu_cs_base; - void __iomem *wrapper_base = hdev->core->wrapper_base; + void __iomem *cpu_cs_base; + void __iomem *wrapper_base; if (!hdev) return IRQ_NONE; + cpu_cs_base = hdev->core->cpu_cs_base; + wrapper_base = hdev->core->wrapper_base; + status = readl(wrapper_base + WRAPPER_INTR_STATUS); if (IS_V6(core)) { if (status & WRAPPER_INTR_STATUS_A2H_MASK || @@ -1650,10 +1653,10 @@ void venus_hfi_destroy(struct venus_core *core) { struct venus_hfi_device *hdev = to_hfi_priv(core); + core->priv = NULL; venus_interface_queues_release(hdev); mutex_destroy(&hdev->lock); kfree(hdev); - core->priv = NULL; core->ops = NULL; }