From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) (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 326FA35AC37 for ; Mon, 3 Aug 2026 22:35:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785796556; cv=none; b=BMesmnO9GlNE7Ia3UQtLFEw7XuAJLmnb2FQumgSpgn+FOW0HrCEUzdghQ5QsjBQHEH27xLPvJjoY49Och7cwOB8rEhhEnzKwTDwOPVuvH19WLycc8XC2dY8HnWcojPyMS9eW+InfaFNwAM32nzz0ZIhpLW9TGZoC3YRhucqgWlE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785796556; c=relaxed/simple; bh=2rJsu8vzK/fLIB+9E81Ec7nDWMQNN/NvO/jTUywhykQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=s1jhQMQMDVG5XSqu+1eKhiJravZZrKeG4vIWFmIl7WByvHIIQHAMlvgivzRZxkBJpckLY5arfSK5AtsBTWc0SESoP5tOeUN/MS6iVyM4iu64CsOeByN+cIhHDQ9AApLg0RTQYHCuDbUR4XVhLWtZUWyv01yAVRy0kKlskRNDIk4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=dM+r2tNw; arc=none smtp.client-ip=209.85.210.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dM+r2tNw" Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-84e507b079dso2800847b3a.0 for ; Mon, 03 Aug 2026 15:35:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785796554; x=1786401354; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=RfXwqy1TgncBxC4BQibRgbXUjLq//9HNL0TAoHIeLvs=; b=dM+r2tNwhd0e2qF5BkT2RFprmsQ9Jze6/ReI234cQF9wRI89oqUE39100KIjAxtLhT ECusBejZ1Am66Jsz4aLb1OWdeJeqx7i+GUfg0ruPcAA8rE3ksvJXM3u5zPXO55IOganX mFes81PSBwBqWaMe7qG31IULg2d26n0LKxx/OihNvY6CltjwefNClK/g5SfYiwRIttnk lVFwgfKchAKaXcLDgokk09jw0F5Lrdcb7OvzYp0X6xjnbvEVkRL8/s5SpqvK80EDSc44 EpXgn70LUOpgdLd1tVXbIFMysqkf/IxiEXXrwi28b6WV0wfTfn47LtNVrOq8LWP1ZRWA wJtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785796554; x=1786401354; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=RfXwqy1TgncBxC4BQibRgbXUjLq//9HNL0TAoHIeLvs=; b=NaX47XsQOwfIUonDyBK3+DSHM5347BCweUK5wxbFGlgWMHoblBU/nIgwMyVHuDaGfa P6Ts+Ghvp8CgklWz+GyVDujSguzxo7tpQqI0AptgcQl565rqYaNh0Tzq9+UUMo9bq+li uPjBLwOCvhipisJWawBf/VPd1FU1yBQV4/CmT+JFPgQ9xPTsROLJcarEFNK47pnLkhhc qZunGQmvKuifFNnJ3ZrksGPQoiknptAi8MCUJpvquxBdu41TbBDoB8Q0x3f4J8DPN/fA 0IcJ9Rf6JNWAiYGj48K9eViHn4BPgG1B29TO8tNO+tqDydXchG1NcZ94Nhfm9pc48znd p8AQ== X-Forwarded-Encrypted: i=1; AHgh+Rrqq27G1AyF+3Q+USqXMxaHKOmIC6WL4RHIe71y2V93UFZg1TbD+M16B6TTrBxtZK3+ZNDEnFCxmMoot4A=@vger.kernel.org X-Gm-Message-State: AOJu0YySmxR286lg3FgEukgs5cGHlDieyFkDaDJoDv6jwdASmug6+V8q AML1IGoBZG60HS2pVVO3D4r6oy0sAxsIQJWTgZcZ/GLYprAT6u96dfwv X-Gm-Gg: AR+sD11CqP+fIjyLZajSBz2R5kVN+c6r8U5rzG2NE2W30Tn6zLEzk9QOnNjrtvpo8Qo dxKafyNLHOZA66RxH+7PsCMgvzGfUifTxXrFXUyxAXtP++TNsNZDoRXm293+Mwg/xaAaE8mEj2e l/MPXtZYxWXiYJupFMeE27K6IrDVGOMqPc30UIIRyXtxu1Q31mdZOYr4ESZWZ0rULNyZi1UQtyT sI9JT+ouCZjTaOy7YdnPde5ifGXCc6M5ZiR/IPneLW9h8Ak0BCSjOmBsP0KKb68Z71puqxUvKyh 3fxujOxDX2Oi5SljtsE6ThmY9UQi2Gx/1jeKAbF6o0Wsvm9eNezn9Ck+ys+A75XzkEWPaUHwSQ3 bjMV8GY8OHHP4+ag0WcaWpNtczhR9xm9FJ0k3qLP7HzHiuNjzsiBfaw5DYaQ5+dCbg96cIUPUH3 T0xpEWgLX8uXUYYN5lytKVsBuyZYDyzuX2/6EHU3kg7sln0o8WJKUngBy0uAmyB0u+QOjHj+3AE TYoWEEj9WwEKGXR3pDq2csChwWmH8IAa0bY+VEpP20c44yG2Y8FhO/H3r2QefeEDnJzJTWK0IF3 rTG+euBzHdBlJufh/9AogCcFymr2GmetTqLOc+HcBJUwv+GF X-Received: by 2002:a05:6a00:1d87:b0:848:6537:580b with SMTP id d2e1a72fcca58-84ee48ef506mr9925893b3a.51.1785796554374; Mon, 03 Aug 2026 15:35:54 -0700 (PDT) Received: from ryzen.lan ([2601:644:8000:7a86::e35]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-84edc2d4473sm4186790b3a.40.2026.08.03.15.35.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Aug 2026 15:35:53 -0700 (PDT) From: Rosen Penev To: linux-gpio@vger.kernel.org Cc: Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , "Christophe Leroy (CS GROUP)" , Linus Walleij , Bartosz Golaszewski , linuxppc-dev@lists.ozlabs.org (open list:LINUX FOR POWERPC (32-BIT AND 64-BIT)), linux-kernel@vger.kernel.org (open list) Subject: [PATCHv2 7/8] gpio: ppc44x: fix undefined behavior in GPIO_MASK2 macro Date: Mon, 3 Aug 2026 15:35:38 -0700 Message-ID: <20260803223539.86303-8-rosenp@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260803223539.86303-1-rosenp@gmail.com> References: <20260803223539.86303-1-rosenp@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Shifting a 32-bit unsigned integer by 32 or more places is undefined behavior in C. GPIO_MASK2 computes its shift amount as (gpio) * 2, and for pins 16-31 in the OSRH/TSRH bank this yields shifts of 32-62. While this happens to work on PowerPC because slw masks the shift count to the low 5 bits, compilers performing value-range propagation may assume the else branch is unreachable and optimize it away, or may evaluate the shift as zero on other architectures via COMPILE_TEST. Mask gpio to the 16-pin bank index so the shift stays within [0, 30]. The registers are banked (OSRL/TSRL for gpio 0-15, OSRH/TSRH for gpio 16-31) with an identical 2-bit-per-pin layout from MSB to LSB, so masking to the within-bank index preserves the intended behavior. Assisted-by: opencode:big-pickle Signed-off-by: Rosen Penev --- drivers/gpio/gpio-ppc44x.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpio/gpio-ppc44x.c b/drivers/gpio/gpio-ppc44x.c index fd543fbb959a..9fdc84e922f4 100644 --- a/drivers/gpio/gpio-ppc44x.c +++ b/drivers/gpio/gpio-ppc44x.c @@ -19,7 +19,7 @@ #include #define GPIO_MASK(gpio) (0x80000000 >> (gpio)) -#define GPIO_MASK2(gpio) (0xc0000000 >> ((gpio) * 2)) +#define GPIO_MASK2(gpio) (0xc0000000 >> (((gpio) % 16) * 2)) /* Physical GPIO register layout */ struct ppc44x_gpio { -- 2.55.0