Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1847131imm; Sat, 29 Sep 2018 05:19:48 -0700 (PDT) X-Google-Smtp-Source: ACcGV61p59Y1c7No4tt7IPamfIdHsUqAdXf1D3GiJL6a6D5QDSy6y5J9ve4y9Cv1Jz2jeQtD2M5B X-Received: by 2002:a17:902:2bc5:: with SMTP id l63-v6mr3063433plb.118.1538223588929; Sat, 29 Sep 2018 05:19:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538223588; cv=none; d=google.com; s=arc-20160816; b=Arw7eMcrKOPdL6ELos22WjfySCXjfMigRXE52mmKGT3o9OKeeWjBvpBy76naLF6sxV ZTsdstj3uq2FBGvaDo9TFV7RZblkcqh4WHmXKX9BDbrQVIKOcdd1b6Lz2MOacbIc7wCi Xg4CN3AJu9hIQihivGEq4WS/IqH1AabVaIeHvpQoDiN1NU1rUPqwsoBmJcq2aW0q1McA FgHIpuQybIFuwuiXWZWiKGRut6vzVzbeLs+HLAA7SWkICyKi8k74z1dM/PvasAwVI5wn BgMjDsnA9sOQ9YBjOwnr4D/nej2SLIbPn0iQTFMp97z0I4lO1A1efdaz0FBGGJ46AGpt py8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=ZKOW8+0FgaclRFDEZ6kADxUMQh2fYfYr5W6bwztBiH8=; b=BuFa7xxCfWYRDX38YnoUvDaAZt4FB2Ax1PSdNBuPCfEVLDmGu6qjdhvVmxHf5OhW89 8MdgqMqUigDrH7pLQte0Ajcdp4NO0FNX3752nbP7fxqVR1fKulnAX+n8RyFpliicPzGT OdPQ9HFeeTEGBukm40rp+fGtcIx5yEVqqRfnRGewWL0Jqm0WPJKpMoriG+VOWo3ceuOP hgImwVR7i9Sq13EXEVe5A0xODL3AdatZU+d5M1OPJ6CisXNaFU7FsP+q9T97533JJ1lE RlNhRZhMy2cyWpqQ1U/bjbp5b45feD+1RLcWzFYmdr8GdwHfXQ/IJq7XNTDkHsVht7AN j1LQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=C2VKbhwn; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y66-v6si7150085pgy.496.2018.09.29.05.19.23; Sat, 29 Sep 2018 05:19:48 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=C2VKbhwn; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728121AbeI2Src (ORCPT + 99 others); Sat, 29 Sep 2018 14:47:32 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:45707 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727637AbeI2Srb (ORCPT ); Sat, 29 Sep 2018 14:47:31 -0400 Received: by mail-lj1-f196.google.com with SMTP id x16-v6so8143690ljd.12; Sat, 29 Sep 2018 05:19:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ZKOW8+0FgaclRFDEZ6kADxUMQh2fYfYr5W6bwztBiH8=; b=C2VKbhwnD6GJ6ayhrmaaB5aqh7KlPYIsrzbH/OJ3n6FZnDgSe7qoVHwudHxHJ/or20 H/HJ4nPLx06af5jFM7ANcvbmzdSK6wNaTSS92mn/E/rmPCxNgkulrgQ4D6CC9AKjAn6Z syIujMCDYCYwuptlEkFrcLfWuxwoJBuYeLHd+Pu+G4T5F3D9W65mYWgYz/ImU0W8YGTQ WD3wyovStKpDrghs4UScfxE7zbxLdgHK3Yfn9UkIaYGO69K901xajfPWBcMcunxU8E/S 5S48y7t4XqvNBvtPpLB+EABtZAxVA9v2MFqLk89jh/0AK7kZcrklQNcsNcAzS7a36lQw 9MuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ZKOW8+0FgaclRFDEZ6kADxUMQh2fYfYr5W6bwztBiH8=; b=jqyyZ5NLMz0q+VKYxM7cFDUt4lkDjWYzsakf0nx0NHOxGMvPbke1gAAXsrxWpOvhUb uh7OqyKtcDy91ReR/vOIPoAvjOQTyxlk3yNmWh6luOvK5MolVpAT8TrpO79n6+iNeN0K wB2rjX2LtHEGI32EPqqe8E3I/EiYZ3gJMjMbdTedsFys2GnI2zJ+lpWwZAS5xhpFAGEa nmuMm7z8x+vhFLrJKCShcp5mmZV12oz2jhqk7PuQ8tSGih+6ge0HM2kV821UQm0eKliQ 7p7T5YvZ/zoKl/Ym75YrgPMUKCLxzoiU5GudQIcMruF4NJtCQtfMGow/F+b2cRuQRimy 50RQ== X-Gm-Message-State: ABuFfojYXntTMz9FwPpjZE066W7ZmKbep2/7lZwdy58fwaAr+H/+6Pgh VDXbpuVENvR4AUj9FwphJNY= X-Received: by 2002:a2e:6353:: with SMTP id x80-v6mr1649114ljb.11.1538223552013; Sat, 29 Sep 2018 05:19:12 -0700 (PDT) Received: from z50.intranet (78-10-164-223.static.ip.netia.com.pl. [78.10.164.223]) by smtp.gmail.com with ESMTPSA id t15-v6sm1536665ljh.21.2018.09.29.05.19.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 29 Sep 2018 05:19:11 -0700 (PDT) From: Janusz Krzysztofik To: Linus Walleij Cc: Miguel Ojeda Sandonis , Peter Korsgaard , Peter Rosin , Ulf Hansson , Andrew Lunn , Florian Fainelli , "David S. Miller" , Dominik Brodowski , Greg Kroah-Hartman , Kishon Vijay Abraham I , Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Hartmut Knaack , Peter Meerwald-Stadler , Jiri Slaby , Willy Tarreau , Geert Uytterhoeven , Sebastien Bourdelin , Lukas Wunner , Rojhalat Ibrahim , Russell King , Tony Lindgren , Yegor Yefremov , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Marek Szyprowski , Krzysztof Kozlowski , linux-gpio@vger.kernel.org, linux-i2c@vger.kernel.org, linux-mmc@vger.kernel.org, netdev@vger.kernel.org, linux-iio@vger.kernel.org, devel@driverdev.osuosl.org, linux-serial@vger.kernel.org, Linux Samsung SOC , linux-kernel@vger.kernel.org, Janusz Krzysztofik Subject: [PATCH] gpiolib: Fix incorrect use of find_next_zero_bit() Date: Sat, 29 Sep 2018 14:20:22 +0200 Message-Id: <20180929122022.6825-1-jmkrzyszt@gmail.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180923235336.22148-2-jmkrzyszt@gmail.com> References: <20180923235336.22148-2-jmkrzyszt@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit b17566a6b08b ("gpiolib: Implement fast processing path in get/set array"), already fixed to some extent with commit 5d581d7e8cdc ("gpiolib: Fix missing updates of bitmap index"), introduced a new mode of processing bitmaps where bits applicable for fast bitmap processing path are supposed to be skipped while iterating bits which don't apply. Unfortunately, find_next_zero_bit() function supposed to skip over those fast bits is always called with a 'start' argument equal to an index of last zero bit found and returns that index value again an again, causing an infinite loop. Fix it by incrementing the index uncoditionally before find_next_zero_bit() is optionally called. Reported-by: Marek Szyprowski Signed-off-by: Janusz Krzysztofik --- Marek, Could you please test it on top of next-20180920 with "gpiolib: Fix missing updates of bitmap index" and optionally "mmc: pwrseq_simple: Fix incorrect handling of GPIO bitmap" also applied? Thanks, Janusz drivers/gpio/gpiolib.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 6ae13e3e05f1..940b543e966d 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -2878,12 +2878,11 @@ int gpiod_get_array_value_complex(bool raw, bool can_sleep, int hwgpio = gpio_chip_hwgpio(desc); __set_bit(hwgpio, mask); + i++; if (array_info) i = find_next_zero_bit(array_info->get_mask, array_size, i); - else - i++; } while ((i < array_size) && (desc_array[i]->gdev->chip == chip)); @@ -2903,12 +2902,11 @@ int gpiod_get_array_value_complex(bool raw, bool can_sleep, value = !value; __assign_bit(j, value_bitmap, value); trace_gpio_value(desc_to_gpio(desc), 1, value); + j++; if (array_info) j = find_next_zero_bit(array_info->get_mask, i, j); - else - j++; } if (mask != fastpath) @@ -3191,12 +3189,11 @@ int gpiod_set_array_value_complex(bool raw, bool can_sleep, __clear_bit(hwgpio, bits); count++; } + i++; if (array_info) i = find_next_zero_bit(array_info->set_mask, array_size, i); - else - i++; } while ((i < array_size) && (desc_array[i]->gdev->chip == chip)); /* push collected bits to outputs */ -- 2.16.4