Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp6276386iob; Tue, 10 May 2022 14:40:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzng4uNAMz8Yko3Jpd644szvQe5W3jrtFxxN0EJSE1ibJen1l3riBt4wDYtgzTe3gRUUMgc X-Received: by 2002:a63:1426:0:b0:3db:11bb:7600 with SMTP id u38-20020a631426000000b003db11bb7600mr1639829pgl.297.1652218824068; Tue, 10 May 2022 14:40:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652218824; cv=none; d=google.com; s=arc-20160816; b=gfh8af76RzxevyDT9bevIEujI6vl9OS1zAPngtV/7TlJdOdNRfq4YZ4ANpCL/QHEsQ 3SXUCG4urc4zvXm1zkkrl6z2ZNDomBHcTQPkwxKMmVNNr/GtTjNkKDYyMjmPuDEIVXbM 4VJzHMiDg5cHKuYSTyObgU0zU7d1l+cHPqSUYJvQKxYwJpOKjgTBZG36iLyTN58uqgEb F5lAj5136jg9fX1TBhOr86L/AHxZBjL5YB4pBUtMLHqbBZHB6pK3mISWpUnnwaxuTx5I qnPJ4LzqBx3GoHkUE+2SLE3BgaLZvmm4qgJ24bXg6sQAxd/WHpW2ZEKobhC9eZxzs0EG ONaw== 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=gZc2iiDx2rfRLopMl1/leQ/PshvhbrQpNvbbubHs621XyasZy54ZD1vNgAixTsHOP7 P+nxjQKk16+L4YGmFlWioBHAaH2tDF0JZVJ7HsIii6TB+5ecagiCpF1rJqFPZxoU5HOK ltppI0NB6nRb6tNSRL4JRMYfZXoewLD03rUvFPdTHbusDod3L2kYwhgK/Fm4bS76MBYj ZOQl3vxuMMMJhO1lTiNIzuFXuUmp6XCa6dlza95TA2Ut1E4sPIL+1lSJ3uIDfZbUlyN5 EdMGtmR9ufLibe5S5XXusqcjHIBQR81aSA1AHM+QlBh5K3STuRUXTipu/nZP9mb/sUFc vhkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=AC+orTsL; 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 cm18-20020a056a00339200b004fa3a8e0053si21911pfb.266.2022.05.10.14.40.07; Tue, 10 May 2022 14:40:24 -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=AC+orTsL; 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 S243822AbiEJNyt (ORCPT + 99 others); Tue, 10 May 2022 09:54:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244534AbiEJNhs (ORCPT ); Tue, 10 May 2022 09:37:48 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05A391129; Tue, 10 May 2022 06:25:52 -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 ams.source.kernel.org (Postfix) with ESMTPS id BEEB7B81DA9; Tue, 10 May 2022 13:25:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1DCB5C385A6; Tue, 10 May 2022 13:25:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1652189147; bh=oXK+xeO7TyS/609kqkxla+MZL2jQ1JRBvy7n7RIohAA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AC+orTsLxEnGuGHyA8ONJWgMRzmeD3nnJhj0x3eq1l5mqzc3Q5bJGkrbGc/CNQsxJ qG7dTk28yg2ZIBnpAD7Abb14L0pVLkjcGggBOH0H+WfmZ5aDYY8xpHPywaQLEC9G63 mCafKJV7ZJeibQFcJ0/3CSwpyiGbHic7gkXdaNwE= 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.10 07/70] gpiolib: of: fix bounds check for gpio-reserved-ranges Date: Tue, 10 May 2022 15:07:26 +0200 Message-Id: <20220510130733.079273199@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220510130732.861729621@linuxfoundation.org> References: <20220510130732.861729621@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);