Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp6294463iob; Tue, 10 May 2022 15:09:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz5cSMlynqXOa/Qv8TY/BvY4pqZx0gm07Tx9tWygUiEmC/Z9f3DtiqTuDR/pKvT0A+XqmR3 X-Received: by 2002:a17:907:d88:b0:6f5:1321:37ed with SMTP id go8-20020a1709070d8800b006f5132137edmr21942016ejc.67.1652220545477; Tue, 10 May 2022 15:09:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652220545; cv=none; d=google.com; s=arc-20160816; b=aipsxV+9FmJ47g2W5OuwRXDgGd+EdfXhOjep4w4rfTd20G4JmOlE5ZAabTN5hs+ZFN uJgcuQlQ979UxjRQlHJ/dq3KapT1BzXbw49MR0ndTX+i0DtQf7Bfdv1eAbbU1L+Lno28 sYx7xWmVCIeDxXid9au92LqObwasOjqrR8bD+30N5EjBp0lwn7vIrKBA5NTxi3h0B461 TVoN5OIQHCj6vkoSE0VDfLsRoElKWOKU1wUM0PiFvqS8aSYKw5d+pzaTwj+V8S3FYZzU eyuk0cyUWlLwrcW/fB1cIClSwC8gPHRJhftn2yY9lMUkjdi/E663rkXk/jvHVrxvfngS v1Pg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=65h4hb2f5lheZ0nJAvd3AjrEdeYk3d5b+w3xWEBLV54=; b=tKB3vCToo1Sv+Kfud4uUTi31mDpUROHnnO+mCbJZxWKYXgWUUqDKdbA+Xm6un1Xo1r DZgsm7BRtVb8XwenIK4gdE6Ak2N5ud0WDhguwOYNLKPERsdRCTUx5Ke+gnBy1nZuEo7j 57VCv4UuQHMCXuktHGKnOzemog8Vb4zpPTY2jK+wF09o66UkByhGQ/Cy+XiMU7QezzRT e91D7Dt7UxFWRacssWxgU3un1uce1ftfZ1ll5rTP2o36OItHCb2+VBZVK4PEzJ9s4ll2 bEi7ZdH6TJOFuSPhZtDfyUvXjE8i9UnjIQqv9jhJ1DuEEWz3ev+DU80EIg+fcHurTbZz tt4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=B95FaSPX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dr3-20020a170907720300b006f3ce72ceb7si455695ejc.531.2022.05.10.15.08.40; Tue, 10 May 2022 15:09:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=B95FaSPX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241912AbiEJOPM (ORCPT + 99 others); Tue, 10 May 2022 10:15:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245292AbiEJNre (ORCPT ); Tue, 10 May 2022 09:47:34 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18D7C4E3BC; Tue, 10 May 2022 06:35:40 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 17414CE1EE2; Tue, 10 May 2022 13:35:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 28ECCC385C2; Tue, 10 May 2022 13:35:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1652189737; bh=oXK+xeO7TyS/609kqkxla+MZL2jQ1JRBvy7n7RIohAA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=B95FaSPXmDw/EfQ2RfrRH+fkUr+iyn/wlxrYkN+BKIduDBfVramYI3FAnWqdgCY94 aceCh/IiKmtJdgVnL5vrJootonoOnOaU2WdFBDu3JbCbLAwfmc7La5nkGFeZGCPdZS CyQH/2MVqHPZQCLV3KnpgStGkkyhFxUFYcAbHTbI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andrei Lalaev , Andy Shevchenko , Linus Walleij , Bartosz Golaszewski Subject: [PATCH 5.17 013/140] gpiolib: of: fix bounds check for gpio-reserved-ranges Date: Tue, 10 May 2022 15:06:43 +0200 Message-Id: <20220510130741.986726495@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220510130741.600270947@linuxfoundation.org> References: <20220510130741.600270947@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andrei Lalaev commit e75f88efac05bf4e107e4171d8db6d8c3937252d upstream. Gpiolib interprets the elements of "gpio-reserved-ranges" as "start,size" because it clears "size" bits starting from the "start" bit in the according bitmap. So it has to use "greater" instead of "greater or equal" when performs bounds check to make sure that GPIOs are in the available range. Previous implementation skipped ranges that include the last GPIO in the range. I wrote the mail to the maintainers (https://lore.kernel.org/linux-gpio/20220412115554.159435-1-andrei.lalaev@emlid.com/T/#u) of the questioned DTSes (because I couldn't understand how the maintainers interpreted this property), but I haven't received a response. Since the questioned DTSes use "gpio-reserved-ranges = <0 4>" (i.e., the beginning of the range), this patch doesn't affect these DTSes at all. TBH this patch doesn't break any existing DTSes because none of them reserve gpios at the end of range. Fixes: 726cb3ba4969 ("gpiolib: Support 'gpio-reserved-ranges' property") Signed-off-by: Andrei Lalaev Reviewed-by: Andy Shevchenko Reviewed-by: Linus Walleij Cc: stable@vger.kernel.org Signed-off-by: Bartosz Golaszewski Signed-off-by: Greg Kroah-Hartman --- drivers/gpio/gpiolib-of.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -912,7 +912,7 @@ static void of_gpiochip_init_valid_mask( i, &start); of_property_read_u32_index(np, "gpio-reserved-ranges", i + 1, &count); - if (start >= chip->ngpio || start + count >= chip->ngpio) + if (start >= chip->ngpio || start + count > chip->ngpio) continue; bitmap_clear(chip->valid_mask, start, count);