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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 41409C433F5 for ; Mon, 28 Feb 2022 12:13:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:From:References:Cc:To: Subject:MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=H8QwC4A2z4RmqPcZV3nSsEmtP6x9tnPgvw2KUIS+uVQ=; b=bQnKn8iCMMKlGh f482T5kMhgrXgKJULE5Wl9hcrMJvsmaJtT17BPkJX+lf2pgl3TUO91rt9SLeChPFn/YmSf8m1Bsd+ JevaMoeQkVZ5WZgNErY4dTZcTm06j2sYKXbLa292scj6JqSavAb8+0T8BzkXGF4ooKVbJJG5V00WQ +f2D5wrlheBeoNF0UzO1KyBhUeUhTPoNqzePuOnb+LmY64xTvj03V9/2v042GIH5otkadVISXF37G E7e5IuMuPlLNrPed/p/sMx1ZrfNZSQyvZRwkuV9e/o/yf573ZD/DvQjKSdI+VeNhMfs4921ve8wZH pIY6J0MUes9jjSSUDzxQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nOesb-00C6DP-34; Mon, 28 Feb 2022 12:11:53 +0000 Received: from smtp-relay-internal-0.canonical.com ([185.125.188.122]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nOeF9-00BtIS-Ar for linux-arm-kernel@lists.infradead.org; Mon, 28 Feb 2022 11:31:10 +0000 Received: from mail-lf1-f72.google.com (mail-lf1-f72.google.com [209.85.167.72]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id A8B2F3F4B4 for ; Mon, 28 Feb 2022 11:30:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1646047859; bh=TqoJaizFHWK8/heI0IG9vgkdj098BV5WNR7J8iP/dOc=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=W2iToTJg+Invz3pkTkECEUAEUQPsv59/iIMHTs2ESJ9wUAuFxzbpfZv5OJaHrm75w 2Tr4hr2rv7K9LKVuxOQzbvK5rB5+u/1LskakSvkc6XeNxPRfY/OrpPhlDXMwuxodsu kvwM2GRg+oEOV6YCssLxflwsHVVrUzSKU8X3kNEzcAmqe3nHHwIVr2m259fjTJOEPd IiPYOe6Kj1zFeTdTsO2lWz8L5yndiPJwH7mjByi8/rnGII2Jmw/DVx83It7uFa6eCa dTLGRsRtQxwyFjc0KMMkqeuanecZLJbkaKBtJ+Xg3uwbwt4i/ooHKJ8VplLEq3zd2H clUfiu9yCfTAw== Received: by mail-lf1-f72.google.com with SMTP id m18-20020a0565120a9200b004439214844dso1641635lfu.9 for ; Mon, 28 Feb 2022 03:30:59 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=TqoJaizFHWK8/heI0IG9vgkdj098BV5WNR7J8iP/dOc=; b=FCC+Hlf0nqlDKdIPc8wWkb88+q0rnDcGu5ZreigJyzjCznWF+CjnoT6FCDkgSaYdF5 URkdtxjX36WIq1aS4gEZFfIA3uipJvoFrEYMkQFVL+JFh3oFo62m/PKYjbYzGIBt1SDl Rpa9SEdozAsDvDb3V+gBKRx4wFbWdbioNdTOxg+/F/RGBv2BUKQq/TJSVBwj2qYQD93n ho9b9y8wDzu0Ssv+SDK2jhmP5iWf+bJ37QT+BHCeetnr6nHaL9h/sL8/HpNQpl+UDWSp PXgUyLbOV26QR80RzlclThsPg7aqZrzAxOTOv7UvJWZa8C3j/ud7RUi6JWyGv16D/uWD BO+A== X-Gm-Message-State: AOAM5333nDr7QlTDWP3TwLmYJhkibzC7OReU18ietPVEP98uoHDxS8F5 71CyoJOPhpUpGNwKklM74E+6i0c7bMHfPOUzWJpQmSIdMT7VhNz2aq27Lh0UcQKv7r/Dgj2IjPM Bpimt15sAt+f6QmHop4j35ofmkfzNpg6zadO5Mm9S2ASBwq55u6Wd X-Received: by 2002:a17:906:69ce:b0:6a7:8c03:3caa with SMTP id g14-20020a17090669ce00b006a78c033caamr14869875ejs.335.1646047848635; Mon, 28 Feb 2022 03:30:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJy8wXt+PKUVmt9ZYqUS8EzsJUeRWG5FxAFTct2htJDic6wAfCk0sPsop3G0sa4LoCQVSlMP6w== X-Received: by 2002:a17:906:69ce:b0:6a7:8c03:3caa with SMTP id g14-20020a17090669ce00b006a78c033caamr14869844ejs.335.1646047848374; Mon, 28 Feb 2022 03:30:48 -0800 (PST) Received: from [192.168.0.133] (xdsl-188-155-181-108.adslplus.ch. [188.155.181.108]) by smtp.gmail.com with ESMTPSA id cc21-20020a0564021b9500b00403bc1dfd5csm6063924edb.85.2022.02.28.03.30.46 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 28 Feb 2022 03:30:47 -0800 (PST) Message-ID: Date: Mon, 28 Feb 2022 12:30:45 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: [PATCH v3 01/11] driver: platform: Add helper for safer setting of driver_override Content-Language: en-US To: Abel Vesa Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" , Stuart Yoder , Laurentiu Tudor , Shawn Guo , Sascha Hauer , Fabio Estevam , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , Wei Liu , Dexuan Cui , Bjorn Helgaas , Bjorn Andersson , Mathieu Poirier , Vineeth Vijayan , Peter Oberparleiter , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Andy Gross , Srinivas Kandagatla , Mark Brown , "Michael S. Tsirkin" , Jason Wang , linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, NXP Linux Team , linux-arm-kernel@lists.infradead.org, linux-hyperv@vger.kernel.org, linux-pci@vger.kernel.org, linux-remoteproc@vger.kernel.org, linux-s390@vger.kernel.org, linux-arm-msm@vger.kernel.org, alsa-devel@alsa-project.org, linux-spi@vger.kernel.org, virtualization@lists.linux-foundation.org, Linus Torvalds , Rasmus Villemoes References: <20220227135214.145599-1-krzysztof.kozlowski@canonical.com> <20220227135214.145599-2-krzysztof.kozlowski@canonical.com> From: Krzysztof Kozlowski In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220228_033107_741015_655D254A X-CRM114-Status: GOOD ( 27.55 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 28/02/2022 11:51, Abel Vesa wrote: > On 22-02-27 14:52:04, Krzysztof Kozlowski wrote: >> 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) >> (do_one_initcall) from [] (kernel_init_freeable+0x3d0/0x4d8) >> (kernel_init_freeable) from [] (kernel_init+0x8/0x114) >> (kernel_init) from [] (ret_from_fork+0x14/0x20) >> >> Provide a helper which clearly documents the usage of driver_override. >> This will allow later to reuse the helper and reduce amount of >> duplicated code. >> >> Convert the platform driver to use new helper and make the >> driver_override field const char (it is not modified by the core). >> >> Signed-off-by: Krzysztof Kozlowski >> --- >> drivers/base/driver.c | 51 +++++++++++++++++++++++++++++++++ >> drivers/base/platform.c | 28 +++--------------- >> include/linux/device/driver.h | 2 ++ >> include/linux/platform_device.h | 7 ++++- >> 4 files changed, 63 insertions(+), 25 deletions(-) >> >> diff --git a/drivers/base/driver.c b/drivers/base/driver.c >> index 8c0d33e182fd..353750b0bbc5 100644 >> --- a/drivers/base/driver.c >> +++ b/drivers/base/driver.c >> @@ -30,6 +30,57 @@ static struct device *next_device(struct klist_iter *i) >> return dev; >> } >> >> +/** >> + * driver_set_override() - Helper to set or clear driver override. >> + * @dev: Device to change >> + * @override: Address of string to change (e.g. &device->driver_override); >> + * The contents will be freed and hold newly allocated override. >> + * @s: NUL terminated string, new driver name to force a match, pass empty >> + * string to clear it >> + * @len: length of @s >> + * >> + * Helper to set or clear driver override in a device, intended for the cases >> + * when the driver_override field is allocated by driver/bus code. >> + * >> + * Returns: 0 on success or a negative error code on failure. >> + */ >> +int driver_set_override(struct device *dev, const char **override, >> + const char *s, size_t len) > > TBH, I think it would make more sense to have this generic > driver_set_override receive only the dev and the string. And then, > each bus type will have their own implementation that handle things > their own way. This would allow all the drivers that will use this to > do something like this: > > ret = driver_set_override(&pdev->dev, "override_string"); > > I think it would look more cleaner. > The interface in general is not for the drivers. Drivers use it in exceptions (few cases in entire kernel) but many times they actually do not need to. Adding a dedicated driver_set_override() brings intention that such usage is welcomed... but it's not. :) Best regards, Krzysztof _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel