Received: by 2002:a25:5b86:0:0:0:0:0 with SMTP id p128csp682415ybb; Thu, 28 Mar 2019 10:05:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqxpqBXtxv5AnmQCvRQFFIzVMGc87YOr3hkFbkFA7lwuKZc1mNN6EyyA+zQZMDV5NVztGZql X-Received: by 2002:a63:3fc8:: with SMTP id m191mr41025713pga.240.1553792732662; Thu, 28 Mar 2019 10:05:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553792732; cv=none; d=google.com; s=arc-20160816; b=m7HBqZiTNsMJvywRTF7QNM+/1woUFofCj02zbztCE3mR+loVV6hB6Q5IzRRraTJyU8 dz1okSebEGw+kWX7mCWgm6znD6KoGWdHf4OgQIqLQwWkVgOmgPNuIdEcIrBkWGVob2g5 pdOdffJ1fG0iKdvcr5qT2AhCKTpdYPpvAEnJXoXj5FM9b8/fAOv6fk1jNF9Q1RaOVdT9 m3Vp7fFtR8fhelyMPsUY5QFMDTv2giQmxgdyyRmUdixDC8RWDX95KAB0Rptg8cuTjBKy yu2lSunSNBp5XQYsSSzB7kk8JjyytyyoTzt0x244XbsC9h9mVJxkVwOTizI+0rTChZOY M7SQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=uLZsTr1ZnTtx8y2x536cBQAkY40/zZXg6Grv3og8mQs=; b=0CnlufL7506mp5YedDsc4mVs/EPqD0XIu4X6oLBysGTUdi3tjslGq6e3ZWIRcvlXON 5GE1kirCiQWVgbs8GNMvc29inlDANQo0R4CEicX1gslIQPkHEWxQ64SiX4Jt1Ro4KBJR eglp8D2dnfVtGq6QIX7gdQEiUEcoGigBd4U9yvBq3DMb17NXiVlfhspSSNJZm13jkhgz oGBF88R8r+626hHTVWwyWSFAhTFxQposj3crb/ZmGeWh3i+2HjUrBL6jXmCMdreRgjS7 cUmnld3BUeC3IVrDMNP7XynEDkA7gFshvmQhNllnz9CkG3FlIUMchaxhrjZj/sdMczU3 DJLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=n7q19ugh; 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=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n79si21507858pfb.133.2019.03.28.10.05.16; Thu, 28 Mar 2019 10:05:32 -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=@linaro.org header.s=google header.b=n7q19ugh; 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=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727140AbfC1REI (ORCPT + 99 others); Thu, 28 Mar 2019 13:04:08 -0400 Received: from mail-lj1-f195.google.com ([209.85.208.195]:36998 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725849AbfC1REH (ORCPT ); Thu, 28 Mar 2019 13:04:07 -0400 Received: by mail-lj1-f195.google.com with SMTP id v13so18334073ljk.4 for ; Thu, 28 Mar 2019 10:04:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=uLZsTr1ZnTtx8y2x536cBQAkY40/zZXg6Grv3og8mQs=; b=n7q19ughZ/g5f03Nqh4DI3xmKH0uyuLkPbSLWrEZQRDrrHwKMpI4s1lx9HJ0rZzDdm z387yDRP9yKJOPNACC35e0UK3rVQfmzkyyehunleGozGGO4XT88l+zzQifYHLJlx2jPN sqXaozyu3lw7K6OmLB81qWMFXWlH7EHSg8VMY9UEoolTJN+RkZvEUm71cfz3w3hSCQKT 6Dlovt8Dxu/+h68jk3dqHLYET2zeuPOhbJOyV8H2LTaPoF+4q7txp8U2xavtYGOIG4Rc ZIeTBx4+HYgzQ+mzMX0uiwLDE2DWpCaUUlaOaJ9uDgsLWefER+bxfMGjB8kNy6q941ds j21g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=uLZsTr1ZnTtx8y2x536cBQAkY40/zZXg6Grv3og8mQs=; b=mihB3zfCSaZco5FAOUbnnSPHn9Ist5jGxwGQLUVDp0W/Q0Bun7G0K95EjI+Hnkx3eR 2lK0ZnvR2SIB7spuOSNn7khwtnx09uoUO3UNjkgoWAe6oMx8Ipl8WeL2XWCOGGYoE+/V mRL2d3reBTcWt9ts4aoTYei2inIlyj7B/Qiu/peolYcXVuTdv/wTZYIL8pdq5m4ovxkD 9R3HJM4wuM82ybi8gun9R6D0Nrm2ysWqE0Qy4+ACH1v0kfJUqF8eSJ9qMWROH8bK7XEH s4C4ftIESdcxWhpV0sH5PFYh6q9AdCU4WIXkPauy+vs/G2xu8dyIVUW5a1Gc9KP3S0KA BvOg== X-Gm-Message-State: APjAAAXFQvOZDMoyMcIXTuRoXtqe9SbAWv1+aa1HMmQI4RyFepARIYEy diHo63586qFjOTIwvUkyJ6NP4vhH3uDQcd5up/5uvQ== X-Received: by 2002:a2e:7d19:: with SMTP id y25mr9437871ljc.126.1553792645453; Thu, 28 Mar 2019 10:04:05 -0700 (PDT) MIME-Version: 1.0 References: <20190328131349.18838-1-geert+renesas@glider.be> <20190328131349.18838-3-geert+renesas@glider.be> In-Reply-To: <20190328131349.18838-3-geert+renesas@glider.be> From: Linus Walleij Date: Thu, 28 Mar 2019 18:03:53 +0100 Message-ID: Subject: Re: [PATCH 2/3] gpio: Fix gpiochip_add_data_with_key() error path To: Geert Uytterhoeven Cc: Bartosz Golaszewski , Benoit Parrot , Laxman Dewangan , Tomeu Vizoso , "open list:GPIO SUBSYSTEM" , "linux-kernel@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 28, 2019 at 2:13 PM Geert Uytterhoeven wrote: > The err_remove_chip block is too coarse, and may perform cleanup that > must not be done. E.g. if of_gpiochip_add() fails, of_gpiochip_remove() > is still called, causing: > > OF: ERROR: Bad of_node_put() on /soc/gpio@e6050000 > CPU: 1 PID: 20 Comm: kworker/1:1 Not tainted 5.1.0-rc2-koelsch+ #407 > Hardware name: Generic R-Car Gen2 (Flattened Device Tree) > Workqueue: events deferred_probe_work_func > [] (unwind_backtrace) from [] (show_stack+0x10/0x14) > [] (show_stack) from [] (dump_stack+0x7c/0x9c) > [] (dump_stack) from [] (kobject_put+0x94/0xbc) > [] (kobject_put) from [] (gpiochip_add_data_with_key+0x8d8/0xa3c) > [] (gpiochip_add_data_with_key) from [] (gpio_rcar_probe+0x1d4/0x314) > [] (gpio_rcar_probe) from [] (platform_drv_probe+0x48/0x94) > > and later, if a GPIO consumer tries to use a GPIO from a failed > controller: > > WARNING: CPU: 0 PID: 1 at lib/refcount.c:156 kobject_get+0x38/0x4c > refcount_t: increment on 0; use-after-free. > Modules linked in: > CPU: 0 PID: 1 Comm: swapper/0 Not tainted 5.1.0-rc2-koelsch+ #407 > Hardware name: Generic R-Car Gen2 (Flattened Device Tree) > [] (unwind_backtrace) from [] (show_stack+0x10/0x14) > [] (show_stack) from [] (dump_stack+0x7c/0x9c) > [] (dump_stack) from [] (__warn+0xd0/0xec) > [] (__warn) from [] (warn_slowpath_fmt+0x44/0x6c) > [] (warn_slowpath_fmt) from [] (kobject_get+0x38/0x4c) > [] (kobject_get) from [] (of_node_get+0x14/0x1c) > [] (of_node_get) from [] (of_find_node_by_phandle+0xc0/0xf0) > [] (of_find_node_by_phandle) from [] (of_phandle_iterator_next+0x68/0x154) > [] (of_phandle_iterator_next) from [] (__of_parse_phandle_with_args+0x40/0xd0) > [] (__of_parse_phandle_with_args) from [] (of_parse_phandle_with_args_map+0x100/0x3ac) > [] (of_parse_phandle_with_args_map) from [] (of_get_named_gpiod_flags+0x38/0x380) > [] (of_get_named_gpiod_flags) from [] (gpiod_get_from_of_node+0x24/0xd8) > [] (gpiod_get_from_of_node) from [] (devm_fwnode_get_index_gpiod_from_child+0xa0/0x144) > [] (devm_fwnode_get_index_gpiod_from_child) from [] (gpio_keys_probe+0x418/0x7bc) > [] (gpio_keys_probe) from [] (platform_drv_probe+0x48/0x94) > > Fix this by splitting the cleanup block, and adding a missing call to > gpiochip_irqchip_remove(). > > Fixes: 28355f81969962cf ("gpio: defer probe if pinctrl cannot be found") > Signed-off-by: Geert Uytterhoeven > --- > I'm not so sure about the need for the call to > gpiochip_irqchip_remove(), as add/remove are not really symmetrical. > Any comments? I need to think about this. Also Mukesh had some comments on naming. I will try to read through the code closer for v2 and figure out if it is what we want to do. But I think we need it. Yours, Linus Walleij