Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1367091rbb; Mon, 26 Feb 2024 07:11:56 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXy3K4fmQv8RCIwqpuZfuQEKc1WwwYDVSdmqwofCrAgZx73d8aYF8Kc3ADXVhUEqguyo/cH+i68oaLR6QI/rLDtj0TaylDvguikjWjggw== X-Google-Smtp-Source: AGHT+IHH5PFbVHdTVhhiYQeppDRSjZEHi0DMWB0YZtznLgZ/OVSuv8JL8ba1mbTCNrXEkYQ/bkB7 X-Received: by 2002:a17:902:d4c8:b0:1db:a94f:903d with SMTP id o8-20020a170902d4c800b001dba94f903dmr7905344plg.36.1708960316399; Mon, 26 Feb 2024 07:11:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708960316; cv=pass; d=google.com; s=arc-20160816; b=sYz4ZSRpmtsY5VYlNq5QTOEcnVV6pYfvLWe1IeGl9xhFq2NKp2WaKcg6mMaueQU22H JHBR3JxrFb0YM4rbmt42WTnX0/fw61R3OqHYZzfQLydUDiF/mKsjMKlRZh7Q08rW/GcL 3V07VBVfI2CO0L/OBf2q2al02I+E7DhduQcTdrjJHbzuKSB0xMbuqQqiBvSDX750HQxP oT5dRxzXFaDC18Es5nf5QZBC6z+LJyGet30ZrN+FCJZB4WGsfnoe4ZCSpQtn1Br5AO2E Uz1WGi8WOhmEXbS0GDt1mwCP77ggS3L4w0uKZWR8oJPNqZ/nhbzzdbWlg4wslYSdHxlZ nM8Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=qsY9uwYPIcTh6fAs4ypgQEXdNt1cbhCWBNSvJ+1zciI=; fh=6RjCGqLJXLrIvlrR9ypQdkk5SpiCLKhPa8q2bpJBIkU=; b=FWDDTvdCj+8WItewAjh6pMp4DKurnTYah1Ui9LlGWUers/nY9tEl4zIksuo3KlZ51J Ag76zR3JTxSt9Jw3I2cP/Q5I24z39UaNdtol9zA8mE39ztclMyksf7jsnqFVbHjR6TrU H01E9HHA1eWrBnuR6LZ2jBerPW6pD1Pwx4WLC6tAjKtPMbfYROZZ0GaJ5iebv6x4cLrm ixBFF/rx2UKmXNoo9YDy/2znySYj3jEI+1VXe/q0vmzPu4iITdy1bRv6fN8748ycxbof g5AxqCsYF8Zl6oDeV3Zk6yZtQn8gKqQjd1I2/5AoinQ/fjFvzx0/V5u4YEXc87tehLPD xmpw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=aladdin.ru dmarc=pass fromdomain=aladdin.ru); spf=pass (google.com: domain of linux-kernel+bounces-81746-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-81746-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aladdin.ru Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id b11-20020a170902d50b00b001dc91aa56fesi2853185plg.537.2024.02.26.07.11.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 07:11:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-81746-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=aladdin.ru dmarc=pass fromdomain=aladdin.ru); spf=pass (google.com: domain of linux-kernel+bounces-81746-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-81746-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aladdin.ru Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 1D81E29D7B2 for ; Mon, 26 Feb 2024 15:11:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1C5E3135A56; Mon, 26 Feb 2024 14:55:36 +0000 (UTC) Received: from mail-out.aladdin-rd.ru (mail-out.aladdin-rd.ru [91.199.251.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CC2FF135419; Mon, 26 Feb 2024 14:55:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.199.251.16 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708959333; cv=none; b=QbPZ9XYkbxWsQhVed7Z9qCcBJp9lPBvmDUA8asnxibuS9BUq8DMXQ5z60nyxoMqMkJcOUUkca/0SgKYb6fBMNtuBD2IhydJWKeo++ECFWbb9/4+ehvtJJwLi8G5B5TPYLDLFDZNx9f2b26X4m8ijIepkG2XfJ+DJM17WKH1zQqE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708959333; c=relaxed/simple; bh=Ra5nRQiwmBuhhUWhWiSbDuLHQ11UKnwbPZndQYrHsgk=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=j2bWaEw7iv/5Ie1q8NlJszmmLnYcsp9RvG0gFgD6z8qWi6w7BXGgAFcqixhywaqhWklxuUWZCC0yKAGRLruFT78EhQh6t9YyD+EHcqySBopdmeHVIPufjte8BwMR4dJrZ0Exn0XQP3ZvGBGb27gY5NBgqLnZ2KFsCHNXE8fSGu4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=aladdin.ru; spf=pass smtp.mailfrom=aladdin.ru; arc=none smtp.client-ip=91.199.251.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=aladdin.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=aladdin.ru From: Daniil Dulov To: Hans de Goede CC: Daniil Dulov , Mark Gross , Andy Shevchenko , Darren Hart , Vadim Pasternak , , , Subject: [PATCH] platform/mellanox: mlxreg-hotplug: Check pointer for NULL before dereferencing it Date: Mon, 26 Feb 2024 17:54:42 +0300 Message-ID: <20240226145442.3468-1-d.dulov@aladdin.ru> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: EXCH-2016-01.aladdin.ru (192.168.1.101) To EXCH-2016-01.aladdin.ru (192.168.1.101) mlxreg_hotplug_work_helper() implies that item can be NULL. There is a sanity check that checks item for NULL and then dereferences it. Even though, the comment before sanity check says that it can only happen if some piece of hardware is broken, but in this case it will lead to NULL-pointer dereference before the function is even called, so let's check it before dereferencing. Found by Linux Verification Center (linuxtesting.org) with SVACE. Fixes: c6acad68eb2d ("platform/mellanox: mlxreg-hotplug: Modify to use a regmap interface") Signed-off-by: Daniil Dulov --- drivers/platform/mellanox/mlxreg-hotplug.c | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/drivers/platform/mellanox/mlxreg-hotplug.c b/drivers/platform/mellanox/mlxreg-hotplug.c index 5c022b258f91..524121b9f070 100644 --- a/drivers/platform/mellanox/mlxreg-hotplug.c +++ b/drivers/platform/mellanox/mlxreg-hotplug.c @@ -348,20 +348,6 @@ mlxreg_hotplug_work_helper(struct mlxreg_hotplug_priv_data *priv, u32 regval, bit; int ret; - /* - * Validate if item related to received signal type is valid. - * It should never happen, excepted the situation when some - * piece of hardware is broken. In such situation just produce - * error message and return. Caller must continue to handle the - * signals from other devices if any. - */ - if (unlikely(!item)) { - dev_err(priv->dev, "False signal: at offset:mask 0x%02x:0x%02x.\n", - item->reg, item->mask); - - return; - } - /* Mask event. */ ret = regmap_write(priv->regmap, item->reg + MLXREG_HOTPLUG_MASK_OFF, 0); @@ -556,7 +542,7 @@ static void mlxreg_hotplug_work_handler(struct work_struct *work) /* Handle topology and health configuration changes. */ for (i = 0; i < pdata->counter; i++, item++) { - if (aggr_asserted & item->aggr_mask) { + if (item && (aggr_asserted & item->aggr_mask)) { if (item->health) mlxreg_hotplug_health_work_helper(priv, item); else -- 2.25.1