From patchwork Mon Feb 26 14:54:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniil Dulov X-Patchwork-Id: 206761 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp2177733dyb; Mon, 26 Feb 2024 08:12:37 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUqjcaNB1jb+k0811jeFN5kwFhv5+BsuEw9VUpxPS9TWacdvyAg5E/o4UtPLVXvKDWFuJKP/0PBnW8WPae5tbcUTd6PQw== X-Google-Smtp-Source: AGHT+IEapEsBmZ6ap8yLtSsyqUbzovZMoXI6V4BSuaBKEtgkbNe0LFtGcFHAgkwz8l6TBLUHjQt6 X-Received: by 2002:a92:dc86:0:b0:365:13af:84ba with SMTP id c6-20020a92dc86000000b0036513af84bamr7929647iln.5.1708963957454; Mon, 26 Feb 2024 08:12:37 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708963957; cv=pass; d=google.com; s=arc-20160816; b=UCWjjP3MqTMa/Gh2lE1DphFKHqJj19C6PyqYZ98+WRfvclib7z3gh/f5vyujBFox+4 SBReGs3HoigT5c7N19n6p+1DV+9dFfhRdmeFT9O0F+XYCJ1MbVbrQDaBGf/EG+RH6dag ayKI7MwcPOIrsUcX9joKwPtigbB+L2jcb2pN/1htqRLk+6n10IOe9APJq1hwJ3xR0M6l rj5I7LdcxhjDlsSqd8WF0HlL617f1cAFnAeKVcFl+YCO+QPlYEDoiRcM4FQxIy3wTKB1 xV7Jax38D0W7mopWeRLP356Ud8c15mZLXg3WG4McDbc5Z/8aVwhNuRDdLoSJJfM/nVzy T2KA== 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-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-81746-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aladdin.ru Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id 2-20020a631942000000b005c688ef7549si3985371pgz.98.2024.02.26.08.12.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 08:12:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-81746-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; 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-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-81746-ouuuleilei=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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 09407B28CC9 for ; Mon, 26 Feb 2024 15:12:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0EBBB135A5D; Mon, 26 Feb 2024 14:55:43 +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 X-ClientProxiedBy: EXCH-2016-01.aladdin.ru (192.168.1.101) To EXCH-2016-01.aladdin.ru (192.168.1.101) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791976455413898385 X-GMAIL-MSGID: 1791978590700514173 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