From patchwork Mon Jan 12 16:12:27 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 427798 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 14DEB140192 for ; Tue, 13 Jan 2015 03:15:39 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752595AbbALQMt (ORCPT ); Mon, 12 Jan 2015 11:12:49 -0500 Received: from mail-lb0-f182.google.com ([209.85.217.182]:64415 "EHLO mail-lb0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752766AbbALQMr (ORCPT ); Mon, 12 Jan 2015 11:12:47 -0500 Received: by mail-lb0-f182.google.com with SMTP id u10so18293453lbd.13; Mon, 12 Jan 2015 08:12:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=t+iobdxw9wFXERslu68+vsNuBwSKrhiX6tI4P+27keU=; b=h243MIyrVuRM3g5F1y96LzISCetmbOXcIxF0D99MXfGPz8AVv1yBn5ldKQNLm+bXhR ymP3snXYpm+9G953qzWR6m+djtSBMOCMD49MGrsBSWSAD06ks5yiyN25dhOH7NKqplLh SWjk/Oh0LasScZbfBnDFskojUKlgo9n9ZY4SKOGPxBm1tcXPqSxP9cukClbEANES0tnE pIJthcWCWnWdGjpgwMOSY802uS8rS72U4gK2ruYp00WIykg4qsPiTuQ958QmnzaxrAdl 8vajPSgOzpXJrHEbCL3omKyVI+VhzWAIxblyjlrIJbit50TVom5nnECFJZUzjRXvKBBe 4ldA== X-Received: by 10.112.130.65 with SMTP id oc1mr37672565lbb.7.1421079165812; Mon, 12 Jan 2015 08:12:45 -0800 (PST) Received: from xi.terra (s83-177-171-8.cust.tele2.se. [83.177.171.8]) by mx.google.com with ESMTPSA id tw3sm3550592lbb.16.2015.01.12.08.12.43 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Jan 2015 08:12:43 -0800 (PST) Received: from johan by xi.terra with local (Exim 4.84) (envelope-from ) id 1YAhbp-0000b6-21; Mon, 12 Jan 2015 17:12:53 +0100 From: Johan Hovold To: Linus Walleij Cc: Alexandre Courbot , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold , stable Subject: [PATCH 4/6] gpio: fix memory leak and sleep-while-atomic Date: Mon, 12 Jan 2015 17:12:27 +0100 Message-Id: <1421079149-2236-5-git-send-email-johan@kernel.org> X-Mailer: git-send-email 2.0.5 In-Reply-To: <1421079149-2236-1-git-send-email-johan@kernel.org> References: <1421079149-2236-1-git-send-email-johan@kernel.org> Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Fix memory leak and sleep-while-atomic in gpiochip_remove. The memory leak was introduced by afa82fab5e13 ("gpio / ACPI: Move event handling registration to gpiolib irqchip helpers") that moved the release of acpi interrupt resources to gpiochip_irqchip_remove, but by then the resources are no longer accessible as the acpi_gpio_chip has already been freed by acpi_gpiochip_remove. Note that this also fixes a few potential sleep-while-atomics, which has been around since 1425052097b5 ("gpio: add IRQ chip helpers in gpiolib") when the call to gpiochip_irqchip_remove while holding a spinlock was added (a couple of irq-domain paths can end up grabbing mutexes). Fixes: afa82fab5e13 ("gpio / ACPI: Move event handling registration to gpiolib irqchip helpers") Fixes: 1425052097b5 ("gpio: add IRQ chip helpers in gpiolib") Cc: stable Signed-off-by: Johan Hovold --- drivers/gpio/gpiolib.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 4efb92ca3463..0f8173051edc 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -327,11 +327,12 @@ void gpiochip_remove(struct gpio_chip *chip) unsigned long flags; unsigned id; + gpiochip_irqchip_remove(chip); + acpi_gpiochip_remove(chip); spin_lock_irqsave(&gpio_lock, flags); - gpiochip_irqchip_remove(chip); gpiochip_remove_pin_ranges(chip); of_gpiochip_remove(chip);