Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4CEFFC433EF for ; Wed, 24 Nov 2021 12:41:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344854AbhKXMnM (ORCPT ); Wed, 24 Nov 2021 07:43:12 -0500 Received: from mail.kernel.org ([198.145.29.99]:39878 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344442AbhKXMke (ORCPT ); Wed, 24 Nov 2021 07:40:34 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id E53596124B; Wed, 24 Nov 2021 12:24:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1637756656; bh=932ShIZqbAb09itBNyyU38a1jRzKzY/mHfIUMBg0pqE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WTbUViBZ8PPS+zq39LLSGJGtWnsyGveZCFsnEstuutmPZImDngnhFZ+aUsAW49rj1 62nnHKDk0zkf4DPDis9Oc7A9hyc4J9UDMQ0UsuXcsi3gUR7ynxtI7uKv/a+49U0vrZ FNmak0afzmVJ0tbQBkyDmfmtBFxZBJQCod5OsI3Y= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Andrew F. Davis" , Hans de Goede , Andy Shevchenko , Sebastian Reichel , Sasha Levin Subject: [PATCH 4.14 159/251] power: supply: bq27xxx: Fix kernel crash on IRQ handler register error Date: Wed, 24 Nov 2021 12:56:41 +0100 Message-Id: <20211124115715.798683402@linuxfoundation.org> X-Mailer: git-send-email 2.34.0 In-Reply-To: <20211124115710.214900256@linuxfoundation.org> References: <20211124115710.214900256@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Hans de Goede [ Upstream commit cdf10ffe8f626d8a2edc354abf063df0078b2d71 ] When registering the IRQ handler fails, do not just return the error code, this will free the devm_kzalloc()-ed data struct while leaving the queued work queued and the registered power_supply registered with both of them now pointing to free-ed memory, resulting in various kernel crashes soon afterwards. Instead properly tear-down things on IRQ handler register errors. Fixes: 703df6c09795 ("power: bq27xxx_battery: Reorganize I2C into a module") Cc: Andrew F. Davis Signed-off-by: Hans de Goede Reviewed-by: Andy Shevchenko Signed-off-by: Sebastian Reichel Signed-off-by: Sasha Levin --- drivers/power/supply/bq27xxx_battery_i2c.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/power/supply/bq27xxx_battery_i2c.c b/drivers/power/supply/bq27xxx_battery_i2c.c index 0b11ed472f338..12ffe62caa17b 100644 --- a/drivers/power/supply/bq27xxx_battery_i2c.c +++ b/drivers/power/supply/bq27xxx_battery_i2c.c @@ -195,7 +195,8 @@ static int bq27xxx_battery_i2c_probe(struct i2c_client *client, dev_err(&client->dev, "Unable to register IRQ %d error %d\n", client->irq, ret); - return ret; + bq27xxx_battery_teardown(di); + goto err_failed; } } -- 2.33.0