From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9BF4D268FD0; Tue, 8 Apr 2025 12:17:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744114665; cv=none; b=b1v1uZOCRACBQvrZ4Ty6gYmn30ytz2lHr/FQB4t4SWBWXPWE++soXcW5QxMf5zd8pUej3LYjeQf0PUFD3ckCDd7cwpskCmJOJXSIIgXyMMH+u6tCvMXufPZyaobXCCuQbnSGnWFuhzZZH7bI1vXNvQWsoTYbyeZh9C+6824U2O0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744114665; c=relaxed/simple; bh=uYxTZEkdaHJVIUf0UaR8nLpg6uTRqmMj41DhwXVsd2g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=c5sYm2cpdiuytPpNdo/cTghVv1Q/egbzJlUeHXrcXL4Eb6EVn5lWX22ZuvrRrchvGQIY+8FHIVmqABaobh9IDcnxfHJiHC4sQKMa2l+FyV3oHI3RaJU7FCEFat4P0lYc9ihxEzs5W3TCARkW4OGOdkuImh0aAZym5MD5AKB6ZyQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=vkgaVpoc; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="vkgaVpoc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E96F8C4AF0B; Tue, 8 Apr 2025 12:17:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1744114665; bh=uYxTZEkdaHJVIUf0UaR8nLpg6uTRqmMj41DhwXVsd2g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vkgaVpocZO4N9ABzhVOmvF9+qp522q7HGDZPuGuoK+bKGQaLF2hAuChRvy+WXJzeX vwmKYqM2UQdGMOMzdwK/QDuItk5zrphiiS0x9gsXM+1c3FxA3Fo51euLmmXDW9w7H9 CHvHMBdimAALAlqFF23V/l1tvuwHapbj8G2vWpm4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Nikita Zhandarovich , Lee Jones , Sasha Levin Subject: [PATCH 6.13 190/499] mfd: sm501: Switch to BIT() to mitigate integer overflows Date: Tue, 8 Apr 2025 12:46:42 +0200 Message-ID: <20250408104855.918842193@linuxfoundation.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250408104851.256868745@linuxfoundation.org> References: <20250408104851.256868745@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.13-stable review patch. If anyone has any objections, please let me know. ------------------ From: Nikita Zhandarovich [ Upstream commit 2d8cb9ffe18c2f1e5bd07a19cbce85b26c1d0cf0 ] If offset end up being high enough, right hand expression in functions like sm501_gpio_set() shifted left for that number of bits, may not fit in int type. Just in case, fix that by using BIT() both as an option safe from overflow issues and to make this step look similar to other gpio drivers. Found by Linux Verification Center (linuxtesting.org) with static analysis tool SVACE. Fixes: f61be273d369 ("sm501: add gpiolib support") Signed-off-by: Nikita Zhandarovich Link: https://lore.kernel.org/r/20250115171206.20308-1-n.zhandarovich@fintech.ru Signed-off-by: Lee Jones Signed-off-by: Sasha Levin --- drivers/mfd/sm501.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/mfd/sm501.c b/drivers/mfd/sm501.c index 0469e85d72cff..7ee293b09f628 100644 --- a/drivers/mfd/sm501.c +++ b/drivers/mfd/sm501.c @@ -920,7 +920,7 @@ static void sm501_gpio_set(struct gpio_chip *chip, unsigned offset, int value) { struct sm501_gpio_chip *smchip = gpiochip_get_data(chip); struct sm501_gpio *smgpio = smchip->ourgpio; - unsigned long bit = 1 << offset; + unsigned long bit = BIT(offset); void __iomem *regs = smchip->regbase; unsigned long save; unsigned long val; @@ -946,7 +946,7 @@ static int sm501_gpio_input(struct gpio_chip *chip, unsigned offset) struct sm501_gpio_chip *smchip = gpiochip_get_data(chip); struct sm501_gpio *smgpio = smchip->ourgpio; void __iomem *regs = smchip->regbase; - unsigned long bit = 1 << offset; + unsigned long bit = BIT(offset); unsigned long save; unsigned long ddr; @@ -971,7 +971,7 @@ static int sm501_gpio_output(struct gpio_chip *chip, { struct sm501_gpio_chip *smchip = gpiochip_get_data(chip); struct sm501_gpio *smgpio = smchip->ourgpio; - unsigned long bit = 1 << offset; + unsigned long bit = BIT(offset); void __iomem *regs = smchip->regbase; unsigned long save; unsigned long val; -- 2.39.5