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 60B2DC4167D for ; Tue, 31 Oct 2023 09:20:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343827AbjJaJUe (ORCPT ); Tue, 31 Oct 2023 05:20:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343829AbjJaJUd (ORCPT ); Tue, 31 Oct 2023 05:20:33 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20049C1 for ; Tue, 31 Oct 2023 02:20:31 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9C498C433C7; Tue, 31 Oct 2023 09:20:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1698744030; bh=Q32Np/6iFGHtqVSVy0gTnmZzfxnsUTtrIV4GPte/htU=; h=Date:From:To:Subject:References:In-Reply-To:From; b=Y9MsBek+pWbg8VLY8K1VsNSZiq2aZjS7zCLkH/UUaeEp7l6zSdj2a1fIYOOgjUqct 8dDkTPz0QcacXMUMWXJ9NCHwSwrOOmx/NxQ3+E/0NG0M7c4Nf8HU0hLEG74msdniPf xflT/YofJcH4BLlfUhezwQVTpcN8PJklLNM2K1Phyc2eNepEumSL+34pdeUcyPtg4u kfQEDYnTVjlfWVg+aJGLPANS+6suBt01752Hj3xvtyrjp5bQB3++eGDzQNUoarRklY y4e2plK6IJ9AGhuL51ANPWo4rKiqVHM6iX4H7W8isSn9fiovgPp8YNchouz0xCvy3N weIqoj23R5MaA== Date: Tue, 31 Oct 2023 09:20:26 +0000 From: Lee Jones To: stable@vger.kernel.org, Krzysztof Kozlowski , "Rafael J . Wysocki" , Greg Kroah-Hartman Subject: Re: [PATCH v5.15.y 1/6] driver: platform: Add helper for safer setting of driver_override Message-ID: <20231031092026.GS8909@google.com> References: <20231031091521.2223075-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: <20231031091521.2223075-1-lee@kernel.org> Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org [Intentional top-post for attention] This is for linux-5.15.y. Apologies for missing the [PATCH 5.15.y] 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: I131f04170f2f76d468565b27929e0ee6fd0e7adf > --- > drivers/base/driver.c | 69 +++++++++++++++++++++++++++++++++ > drivers/base/platform.c | 28 ++----------- > include/linux/device/driver.h | 2 + > include/linux/platform_device.h | 6 ++- > 4 files changed, 80 insertions(+), 25 deletions(-) [...] -- Lee Jones [李琼斯]