From patchwork Sat Feb 20 05:13:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bamvor Zhang X-Patchwork-Id: 62448 Delivered-To: patch@linaro.org Received: by 10.112.43.199 with SMTP id y7csp169313lbl; Fri, 19 Feb 2016 21:13:55 -0800 (PST) X-Received: by 10.66.100.196 with SMTP id fa4mr23205184pab.37.1455945234884; Fri, 19 Feb 2016 21:13:54 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 127si21213499pfa.202.2016.02.19.21.13.54; Fri, 19 Feb 2016 21:13:54 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-owner@vger.kernel.org; dkim=neutral (body hash did not verify) header.i=@gmail.com; dmarc=fail (p=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752023AbcBTFNp (ORCPT + 4 others); Sat, 20 Feb 2016 00:13:45 -0500 Received: from mail-pa0-f41.google.com ([209.85.220.41]:35407 "EHLO mail-pa0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756806AbcBTFNo (ORCPT ); Sat, 20 Feb 2016 00:13:44 -0500 Received: by mail-pa0-f41.google.com with SMTP id ho8so62811077pac.2 for ; Fri, 19 Feb 2016 21:13:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=EIQmSQDabyAtaHGtGdMczFa5qp0L2puTyHqVizwnbzo=; b=LSHKXfmn8ZmehxtoAuIwkmXytowpnXgUeC+hyjCKtTGfvt2Rjg+xZO56lmPrRI96yf eb3AD1gD/JoKvS50QtSNyv0vOOwSl9YSoC2bXYqeUjmvRo8kbyUK5ttd1AS20ILQ/RVp zQ3LRAA9jzT1S98YyKYt1Bc7JYMhqjz/dkhq/Y1T89auPG6IJEM1ny62+ciwSs3UWYI9 7V0lMueGTRZExEaCXPsGhJVf6/VIR0om3D7RLIUF+Q80R/i8/9IS+9bmPaeShnr54D48 FQkglJJwM0x+e6StkKj+FBzocz2aMGtMZ2qPD/c9EsNZsSkL85yVIT9Arif8q0opzvyf sMmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=EIQmSQDabyAtaHGtGdMczFa5qp0L2puTyHqVizwnbzo=; b=BWcdhld8G3rHooOnZQZrIi48nSMjsAifI9V9eVgDBjJc+djGInr3V11V3r2hTp39mi McfiOaEvIPffoBYgCDRWe0TG+QsuNlK3ORid+gQhPux7igRBt6aeKqXgZZXp63bgvMqG ldMPSRzxfCVVsfXjmtmyohKVp2WQycUsSK56ib4hG+QSaE8ltE8p11RtN4hoZjXSK49k 3JAgmgFqgM1imuiTB80AY1SViyRtgkL+NPe/Z6KhYcGX9lreIyMPQR8FCXCW+KQ1vEaB RmOntNL46nMR30zizZPoNo9r4s3ZVhDvoeHS6Y0Xf0H0zqv5HN5QebCTPO9weOMwI6gt +3Sg== X-Gm-Message-State: AG10YOTXJ/5Z3bJjQTHbIP12ay3MITphqq6IVG1XpbAPDPCxzjVj9hEzhrwI7BGvDoyEJQ== X-Received: by 10.66.190.40 with SMTP id gn8mr23094202pac.64.1455945223860; Fri, 19 Feb 2016 21:13:43 -0800 (PST) Received: from linux-5iys.suse ([205.147.105.74]) by smtp.gmail.com with ESMTPSA id x13sm21241956pfa.72.2016.02.19.21.13.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 19 Feb 2016 21:13:43 -0800 (PST) From: Bamvor Jian Zhang To: linux-gpio@vger.kernel.org Cc: linus.walleij@linaro.org, broonie@kernel.org, Bamvor Jian Zhang Subject: [PATCH] gpiolib: fix crash when gpiochip removed Date: Sat, 20 Feb 2016 13:13:19 +0800 Message-Id: <1455945199-5068-1-git-send-email-bamv2005@gmail.com> X-Mailer: git-send-email 2.6.2 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bamvor Jian Zhang Commit cb464a88e1ed ("gpio: make the gpiochip a real device") call gpiochip_sysfs_unregister after the gpiochip is empty. It lead to the following crash: [ 163.503994] Unable to handle kernel NULL pointer dereference at virtual address 0000007c [...] [ 163.525394] [] gpiochip_sysfs_unregister+0x44/0xa4 [ 163.525611] [] gpiochip_remove+0x24/0x154 [ 163.525861] [] mockup_gpio_remove+0x38/0x64 [gpio_mockup] [ 163.526101] [] platform_drv_remove+0x24/0x64 [ 163.526313] [] __device_release_driver+0x7c/0xfc [ 163.526525] [] driver_detach+0xbc/0xc0 [ 163.526700] [] bus_remove_driver+0x58/0xac [ 163.526883] [] driver_unregister+0x2c/0x4c [ 163.527067] [] platform_driver_unregister+0x10/0x18 [ 163.527284] [] mock_device_exit+0x10/0x38 [gpio_mockup] [ 163.527593] [] SyS_delete_module+0x1b8/0x1fc [ 163.527799] [] __sys_trace_return+0x0/0x4 [ 163.528049] Code: 940d74b4 f9019abf aa1303e0 940d7439 (7940fac0) [ 163.536273] ---[ end trace 3d1329be504af609 ]--- This patch fix this by changing the code back. Signed-off-by: Bamvor Jian Zhang --- drivers/gpio/gpiolib.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) -- 2.6.2 -- To unsubscribe from this list: send the line "unsubscribe linux-gpio" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 59f0045..7181807 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -624,11 +624,10 @@ void gpiochip_remove(struct gpio_chip *chip) unsigned i; bool requested = false; - /* Numb the device, cancelling all outstanding operations */ - gdev->chip = NULL; - /* FIXME: should the legacy sysfs handling be moved to gpio_device? */ gpiochip_sysfs_unregister(gdev); + /* Numb the device, cancelling all outstanding operations */ + gdev->chip = NULL; gpiochip_irqchip_remove(chip); acpi_gpiochip_remove(chip); gpiochip_remove_pin_ranges(chip);