From mboxrd@z Thu Jan 1 00:00:00 1970 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 647CFC4332F for ; Tue, 31 Oct 2023 09:36:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343942AbjJaJgW (ORCPT ); Tue, 31 Oct 2023 05:36:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343945AbjJaJgW (ORCPT ); Tue, 31 Oct 2023 05:36:22 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC4ECDA for ; Tue, 31 Oct 2023 02:36:18 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 69DA5C433C8; Tue, 31 Oct 2023 09:36:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1698744978; bh=gIUQPI84A5HML5wG0diw0E/tir2s/mnqT/gcDbIkBW8=; h=Date:From:To:Subject:References:In-Reply-To:From; b=OlpLu9gcVteNDYcTAJ0tTI2van3K1Oluo5kGFRMQzlBJeL8V3AIj2B5TZ26v2Gnnl x3z74lnsahrswi7dQwyNny15m72NlSgUJkX6t/21Qqkyzorha+TQFEiuRz0JAUvOCs xPGVP8zFSBLxC8eqv6QNU8dRy+O9AMdNSxiIQJ5b5mfNw//XXG/agFtAuCUv9w0bA3 j/Ksr2wi6/szznnjxSy9gynsL/7EthO/2ZmX2YA533o+TmitJDzbdLw14KoODClAfI DemlHI5nLAPNc6Mr8QwnGHNqPn9vknHkNN4rPd1MTdMa08wctV4nQyJb6SrOU6uAMM DHwXk+4Skpvbg== Date: Tue, 31 Oct 2023 09:36:14 +0000 From: Lee Jones To: stable@vger.kernel.org, Krzysztof Kozlowski , "Rafael J . Wysocki" , Greg Kroah-Hartman Subject: Re: [PATCH v4.19.y 1/6] driver: platform: Add helper for safer setting of driver_override Message-ID: <20231031093614.GT8909@google.com> References: <20231031093018.2233640-1-lee@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20231031093018.2233640-1-lee@kernel.org> Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org On Tue, 31 Oct 2023, Lee Jones wrote: > From: Krzysztof Kozlowski > > commit 6c2f421174273de8f83cde4286d1c076d43a2d35 upstream. > > Several core drivers and buses expect that driver_override is a > dynamically allocated memory thus later they can kfree() it. > > However such assumption is not documented, there were in the past and > there are already users setting it to a string literal. This leads to > kfree() of static memory during device release (e.g. in error paths or > during unbind): > > kernel BUG at ../mm/slub.c:3960! > Internal error: Oops - BUG: 0 [#1] PREEMPT SMP ARM > ... > (kfree) from [] (platform_device_release+0x88/0xb4) > (platform_device_release) from [] (device_release+0x2c/0x90) > (device_release) from [] (kobject_put+0xec/0x20c) > (kobject_put) from [] (exynos5_clk_probe+0x154/0x18c) > (exynos5_clk_probe) from [] (platform_drv_probe+0x6c/0xa4) > (platform_drv_probe) from [] (really_probe+0x280/0x414) > (really_probe) from [] (driver_probe_device+0x78/0x1c4) > (driver_probe_device) from [] (bus_for_each_drv+0x74/0xb8) > (bus_for_each_drv) from [] (__device_attach+0xd4/0x16c) > (__device_attach) from [] (bus_probe_device+0x88/0x90) > (bus_probe_device) from [] (device_add+0x3dc/0x62c) > (device_add) from [] (of_platform_device_create_pdata+0x94/0xbc) > (of_platform_device_create_pdata) from [] (of_platform_bus_create+0x1a8/0x4fc) > (of_platform_bus_create) from [] (of_platform_bus_create+0x20c/0x4fc) > (of_platform_bus_create) from [] (of_platform_populate+0x84/0x118) > (of_platform_populate) from [] (of_platform_default_populate_init+0xa0/0xb8) > (of_platform_default_populate_init) from [] (do_one_initcall+0x8c/0x404) > > Provide a helper which clearly documents the usage of driver_override. > This will allow later to reuse the helper and reduce the amount of > duplicated code. > > Convert the platform driver to use a new helper and make the > driver_override field const char (it is not modified by the core). > > Reviewed-by: Rafael J. Wysocki > Acked-by: Rafael J. Wysocki > Signed-off-by: Krzysztof Kozlowski > Link: https://lore.kernel.org/r/20220419113435.246203-2-krzysztof.kozlowski@linaro.org > Signed-off-by: Greg Kroah-Hartman > Signed-off-by: Lee Jones > Change-Id: I2f59769cfb99d8359d14e2cb7345ce3428593afc Disregard this set please! I'm pre-coffee and operated in the wrong kernel directory with the incorrect `commit-msg` enabled. > --- > drivers/base/driver.c | 69 +++++++++++++++++++++++++++++++++ > drivers/base/platform.c | 28 ++----------- > include/linux/device.h | 2 + > include/linux/platform_device.h | 6 ++- > 4 files changed, 80 insertions(+), 25 deletions(-) -- Lee Jones [李琼斯]