Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3094104pxb; Mon, 1 Mar 2021 01:09:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJxp6Jefej157lrg0HUd1TKwzPKNrPCENTX2pFB4/eJAbK5TRYLeD6lpP8RqXzty0pgZEKEj X-Received: by 2002:a05:6402:510d:: with SMTP id m13mr15919044edd.330.1614589740936; Mon, 01 Mar 2021 01:09:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614589740; cv=none; d=google.com; s=arc-20160816; b=XzrJKsgrxKE0kBEDsF4k7L2aJyXDJkQ5510ejAvD8mrNVA6VqUSPQsp7MitP9TAdaZ DeCfL51HT8fMkIfTYLB6f2fAqOajIBG4Afl1mydW4S03OHekwZilC4JsnxXDs47zYwVn Qb5i7h8n1+ANpQNFEz5tg5jDGVjQ4/0zOEkYvDRG/G7mk0jQV/DAPvOR9q3siZQAtgxq 6WcIpi0b2KvKDbYkfQqq/hTL4I0OracFkij4r89zMoxpje0DlicJcQnEkLHvVTU08ewt lS/BfZVl0JzbhFGgN+v//EPUmbvOu5j3VS4iSoNT2GNf1xx0LQhCWYlkDR38ZGOeRQWS 1hQw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=mZI7sVRP/tn+v2fkCrUtbh8qKevnkKC+dSx99sv2BTU=; b=yzFqHGApxhhs62Ghey7YKI1FFqCGbqYKsIRcHbQvt/jvW5AQGZxqPw/ehlRMY/ZPoz tnjBIpE4j6aKtIsxf8iDBKjtejUh9ovF11tdJsSMBBaDIupCQb48QYSV1H73c6oXlSAC jrkQ34kaavDQDrTLW5kZlp5Ily4H6JkL+bl//5ya3GalLJJqPM/rO8PcTR8mJLj0nErT pXRUxpKfR+ak4APJ7wNuLcr4MkOGpQ4ucqMSxRroDXuMH+T0+Lr1eidQ244j37g5QHe/ USZ533uCgtpW0yet6xUONMZDhv/GImikTpG3nrGtozjFumr3j8rZn1+rLsMD4lYUGFEy HFpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nSPNlYQI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r9si2657720ejx.201.2021.03.01.01.08.38; Mon, 01 Mar 2021 01:09:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nSPNlYQI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233537AbhCAJHO (ORCPT + 99 others); Mon, 1 Mar 2021 04:07:14 -0500 Received: from mail.kernel.org ([198.145.29.99]:38060 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233703AbhCAJFt (ORCPT ); Mon, 1 Mar 2021 04:05:49 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8369864E01; Mon, 1 Mar 2021 09:05:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1614589508; bh=MZS+vEFMJfhOIBzq9iXKTlDqzsIfvu2g36hJM0R+3u8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nSPNlYQIJ5RPGN2tOwO2XcDRcIq7qsYe6seUFzMl+43ZPfLHt5Qs8Zc9NIAxa3Sd0 iSeYwM68ZDad+/L1fkJK18PKcNSjr4r03oXhCSQUCzHRRvkFj747loFrXKiG15TM7n Uq15eSvrljHoiGg5+S7NwhFv8GnwYAstkMqQQN453h2R3lCbsKOgUKZQbJxhGBpS3W yCa36EtVJWTzSzwPz7lOidmb5usLs6W1Ln4Q2Z8XZOHQ3D3i1aC6x6en6V+lJW5r1a jpjTwj4RlUlFUKriVtfDjoQQ/eem2gW+hSvkG1zf+R0StEC2+CHXnpo9zvpl2PA9IS MmsxXcyg16c7g== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1lGeUY-0006pL-8h; Mon, 01 Mar 2021 10:05:26 +0100 From: Johan Hovold To: Linus Walleij , Bartosz Golaszewski Cc: Greg Kroah-Hartman , Saravana Kannan , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold , stable@vger.kernel.org Subject: [PATCH v2 2/2] gpio: fix gpio-device list corruption Date: Mon, 1 Mar 2021 10:05:19 +0100 Message-Id: <20210301090519.26192-3-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210301090519.26192-1-johan@kernel.org> References: <20210301090519.26192-1-johan@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Make sure to hold the gpio_lock when removing the gpio device from the gpio_devices list (when dropping the last reference) to avoid corrupting the list when there are concurrent accesses. Fixes: ff2b13592299 ("gpio: make the gpiochip a real device") Cc: stable@vger.kernel.org # 4.6 Reviewed-by: Saravana Kannan Signed-off-by: Johan Hovold --- drivers/gpio/gpiolib.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 6e0572515d02..4253837f870b 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -475,8 +475,12 @@ EXPORT_SYMBOL_GPL(gpiochip_line_is_valid); static void gpiodevice_release(struct device *dev) { struct gpio_device *gdev = container_of(dev, struct gpio_device, dev); + unsigned long flags; + spin_lock_irqsave(&gpio_lock, flags); list_del(&gdev->list); + spin_unlock_irqrestore(&gpio_lock, flags); + ida_free(&gpio_ida, gdev->id); kfree_const(gdev->label); kfree(gdev->descs); -- 2.26.2