Message ID | a4af764e-990b-4ebd-b342-852844374032@moroto.mountain |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-86736-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2097:b0:108:e6aa:91d0 with SMTP id gs23csp384084dyb; Thu, 29 Feb 2024 05:15:36 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWZ3U6kI4YnSxGr24w3uU2gf2CjUtj9qSTK0O2XXwn0ltQ0Tg8b5ODS1vsukiA2dejFq3nVreELBGL9YQiUhDkoAp0bwA== X-Google-Smtp-Source: AGHT+IFORDQoKGis7s4MHjOQ1iUdQeaF0KPD+1f7AYRGPYnxQR26Ecid3UHaNmdt+D8T2FAN1WcG X-Received: by 2002:a92:dcc7:0:b0:365:1d6b:7c67 with SMTP id b7-20020a92dcc7000000b003651d6b7c67mr2369394ilr.12.1709212536104; Thu, 29 Feb 2024 05:15:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709212536; cv=pass; d=google.com; s=arc-20160816; b=cjN5GcxnNv3EcaEUuKaXb6zUk0OQoE5oKD6GPfZz9Ur0eDo/6JMZb/o/UUejg+6u3B fg4QY2ScnoYHPq0ExJCUoqZEQdSpXsVdEICr/ezW97Fv8pih4BkD7BfraTOpWTdGST+j 8nIPng4w8B2PUhDLWsjWBpYdV5SQEbyIAFJt+ES+rtY5iIn0ypy0Bu43i71vQbF08lX+ f9/BoApI8LpdDQbczffyV5hldtJ4yndFusDbAnV4du7rKnUKDbU6Nog8QiQRnPxQeI8J Ujf1CwWz/Z8aUYeyqlGdNU4FgXcE/xgzdJceII79px6KZ6DJFwgWEhkUHti/3KbpHfVr 2F6Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-disposition:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:message-id:subject:cc:to:from:date :dkim-signature; bh=Lg2hnToVZ/EBQAxgZOoEwHDmIEWKGQv1sU1Wb9UKAB0=; fh=fypR/Z4o4IPIrt7CeVAaSDdTk2uEqvmGhcYRRuEHj98=; b=MC5IENJIPM9eZn4GLT0i4B6X9jjG6H/GACEPOYlHsCFne/utvvllMT6sVWn5y7XtRS c4ioXxytLQQUoEnzsn9+N8ZyMoYHX1RILfmJJVAlV5ZHDy9UvFolv5hTXAkwLEE6fJiN REd0cxR7Cg4CN+4DsZ7EYfgRxgS7o9NPbYttMYf95mXgPZchcCKKQTEQL7Mo2h6MbMXU ucGFAPEpWtIleYfZ6JrXqqbuZ/ksjlCxKEDMWoFBqXBKPCHvhocP7PaMnsCWkJo8nUKH bIGUYxWh2NeskSaZ01sAdczFahFJtT1RAC1bFi9DsyXJ5tcB6eMrLyR4JDafEoE/yHYd uGMA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DcMO1HHt; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-86736-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-86736-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id ay17-20020a056a00301100b006e4e05b9a5dsi1330966pfb.37.2024.02.29.05.15.35 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 05:15:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-86736-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DcMO1HHt; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-86736-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-86736-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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 9E1EBB25334 for <ouuuleilei@gmail.com>; Thu, 29 Feb 2024 13:11:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8F7EF5F489; Thu, 29 Feb 2024 13:11:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="DcMO1HHt" Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (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 C80F97E0F9 for <linux-kernel@vger.kernel.org>; Thu, 29 Feb 2024 13:11:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709212305; cv=none; b=Z4Y/CholFhwqmAiUC8Qx1WGId1nAtOPpvM/rM4PiQGv4iOYfnfQKvT/afszVhmSCrUWTckrg4G4B4j4H99I50COVcRW6HuxJkuJnq1iNyotvmNXMnQ/KJH5Bm47FJe+kECEOl/LW9VO407jua/3pM9jLPB8QtgE8/OY3zgh3ukQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709212305; c=relaxed/simple; bh=lQEzSztbGwuMcXFF6UoVbrUM+PR6UEuexVzSDmGCcRI=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=rmhPgD4oJdwp87ex8mqlrc2QwUbPI4SK7CALS0IhE73SZOcuRC2kSFupsXrKuYYmmF5cZpVcbBosQT/RxBmRC9O4XDn9dHAQBS0FFupm27p6x5pOMl2Ql94ntxu5KzfceSd0XRKqbhh8w8E9EW8VY3ssNJWmv5NB2YnNtQbDfQA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=DcMO1HHt; arc=none smtp.client-ip=209.85.128.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-412aec2505dso6328075e9.2 for <linux-kernel@vger.kernel.org>; Thu, 29 Feb 2024 05:11:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709212301; x=1709817101; darn=vger.kernel.org; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=Lg2hnToVZ/EBQAxgZOoEwHDmIEWKGQv1sU1Wb9UKAB0=; b=DcMO1HHtRTX6QJOoTLOMlxgbshExarEF6zmAzlNZGW6Ffw38fZMv4hBvFm2heWxTex ZNz/Y5/703WBmemRR4ODRgRIiXn5ruW+KkqY72++NnNAaLw+ioexydWpGR16diwu0rBH XaDeJdL1cmWr/6uJLudpP5gjbt7OWWI4ufPrbfmMMb67IcJwILxPG08OLsWEL+bS7VQK vg/ZKg7dK12DrmpDLSXEnUuGtJUcePyubOGU4IDsWVe5aqa0cNZF+kadi5A/u3zLGwYy SI6/Hy4AJ/Hxq0Cn1V5v/n0a8GnQ+j4dalvUTtYCYpwF8vtPDlDp4Wb8aMfbMEp9mq02 tWDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709212301; x=1709817101; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Lg2hnToVZ/EBQAxgZOoEwHDmIEWKGQv1sU1Wb9UKAB0=; b=EWE0daHQQl5dHnov+meKRF6IQ61cBrnmNOItIQf/Nujxqe0P3kSX/7PYgH4LEHyVmu H3ME63KE/DJUbmdbObROjhJNqvj0D6hSReoApdtOmll4Wu1P+fGSZ4+1HthersCeJ0tL NLXv/Th1hWNOocjkAgWXZfmuBDWRhzO31kDXu7qb+n4ejohWAfZmLW0lEIWZXsTARYdw qU+jYz3/+OqamRcXHV0lGpA+uKjcgoQKzLgDtN8r5ncALtU1QC2nv88E/VzKsmfeYllE 2f7LwpdO0oh6Q/mUc5oIjguOz7BJeh1zz2fJb/pwSJRg544C9XgFghu4eRuGFmlvNLOK jWwg== X-Forwarded-Encrypted: i=1; AJvYcCX0eeYawAadsfoKN0l56EtndfhfeH+Ii08f99hvavBMwhPO4FSOR/hIaXrzyoEp2U9+viC9TfXE1/cOY1hJ7kj+KPY8Hf/kScgVPpE0 X-Gm-Message-State: AOJu0Yy8n0RBeePjpOgLmBbTe5B0QUYWFuxo8MOry+d80rzb0fdryQ3t BRCjPkr8XlbLONHntY4h/jNuz/6Tmj9tcxtpu3Dvyni/GW+Vj5J9gP1TPhsj60o= X-Received: by 2002:a05:600c:4587:b0:412:bdc1:d0f9 with SMTP id r7-20020a05600c458700b00412bdc1d0f9mr1300832wmo.38.1709212301127; Thu, 29 Feb 2024 05:11:41 -0800 (PST) Received: from localhost ([102.222.70.76]) by smtp.gmail.com with ESMTPSA id jp21-20020a05600c559500b004126101915esm5165227wmb.4.2024.02.29.05.11.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 05:11:40 -0800 (PST) Date: Thu, 29 Feb 2024 16:11:36 +0300 From: Dan Carpenter <dan.carpenter@linaro.org> To: Shravan Kumar Ramani <shravankr@nvidia.com> Cc: Hans de Goede <hdegoede@redhat.com>, Ilpo =?iso-8859-1?q?J=E4rvinen?= <ilpo.jarvinen@linux.intel.com>, Vadim Pasternak <vadimp@nvidia.com>, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [PATCH] platform/mellanox: mlxbf-pmc: fix signedness bugs Message-ID: <a4af764e-990b-4ebd-b342-852844374032@moroto.mountain> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Mailer: git-send-email haha only kidding X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792239244075031683 X-GMAIL-MSGID: 1792239244075031683 |
Series |
platform/mellanox: mlxbf-pmc: fix signedness bugs
|
|
Commit Message
Dan Carpenter
Feb. 29, 2024, 1:11 p.m. UTC
These need to be signed for the error handling to work. The
mlxbf_pmc_get_event_num() function returns int so int type is correct.
Fixes: 1ae9ffd303c2 ("platform/mellanox: mlxbf-pmc: Cleanup signed/unsigned mix-up")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
The code in mlxbf_pmc_valid_range() has a check for negatives but that
has a signedness bug too. Fortunately "(u32)-EINVAL + 8" will not
result in an integer overflow so the offset is treated as invalid.
drivers/platform/mellanox/mlxbf-pmc.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
Comments
On Thu, 29 Feb 2024 16:11:36 +0300, Dan Carpenter wrote: > These need to be signed for the error handling to work. The > mlxbf_pmc_get_event_num() function returns int so int type is correct. > > Thank you for your contribution, it has been applied to my local review-ilpo branch. Note it will show up in the public platform-drivers-x86/review-ilpo branch only once I've pushed my local branch there, which might take a while. The list of commits applied: [1/1] platform/mellanox: mlxbf-pmc: fix signedness bugs commit: d22168db08c4c8e6c5e25fa3570f50f0f2ff1ef1 -- i.
On Thu, 29 Feb 2024, Dan Carpenter wrote: > These need to be signed for the error handling to work. The > mlxbf_pmc_get_event_num() function returns int so int type is correct. > > Fixes: 1ae9ffd303c2 ("platform/mellanox: mlxbf-pmc: Cleanup signed/unsigned mix-up") > Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org> > --- > The code in mlxbf_pmc_valid_range() has a check for negatives but that > has a signedness bug too. Fortunately "(u32)-EINVAL + 8" will not > result in an integer overflow so the offset is treated as invalid. Hi, While this patch itself was fine so I applied it, when reviewing the patch I noticed that some of the kstrtouint() derived values were not properly bound checked (some were fed directly to FIELD_PREP()).
diff --git a/drivers/platform/mellanox/mlxbf-pmc.c b/drivers/platform/mellanox/mlxbf-pmc.c index 250405bb59a7..bc91423c96b9 100644 --- a/drivers/platform/mellanox/mlxbf-pmc.c +++ b/drivers/platform/mellanox/mlxbf-pmc.c @@ -1496,8 +1496,9 @@ static ssize_t mlxbf_pmc_counter_show(struct device *dev, { struct mlxbf_pmc_attribute *attr_counter = container_of( attr, struct mlxbf_pmc_attribute, dev_attr); - unsigned int blk_num, cnt_num, offset; + unsigned int blk_num, cnt_num; bool is_l3 = false; + int offset; u64 value; blk_num = attr_counter->nr; @@ -1530,9 +1531,10 @@ static ssize_t mlxbf_pmc_counter_store(struct device *dev, { struct mlxbf_pmc_attribute *attr_counter = container_of( attr, struct mlxbf_pmc_attribute, dev_attr); - unsigned int blk_num, cnt_num, offset, data; + unsigned int blk_num, cnt_num, data; bool is_l3 = false; u64 evt_num; + int offset; int err; blk_num = attr_counter->nr; @@ -1612,8 +1614,9 @@ static ssize_t mlxbf_pmc_event_store(struct device *dev, { struct mlxbf_pmc_attribute *attr_event = container_of( attr, struct mlxbf_pmc_attribute, dev_attr); - unsigned int blk_num, cnt_num, evt_num; + unsigned int blk_num, cnt_num; bool is_l3 = false; + int evt_num; int err; blk_num = attr_event->nr;