From patchwork Wed Mar 16 15:05:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 12782771 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 8ECF2C433F5 for ; Wed, 16 Mar 2022 15:08:29 +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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=6blOBdUUpMOxGMaa9VU7LfQWVvI1EVjGPlyyoegWvFw=; b=SUORGPUQqCLaUv DJLwMhGCXov/rUJPh8CSebxp2ZRXNu2mzUhD7eWcdD/LNAgRpSK7gI0vNcEaw90x6majmwUfGWIpR 3FHWm1OjrjuRpSS8kYP7aqlFU1kEGG3wY9IwJGmG6oNuujAJGnofrg3kpsxMKKfFG/r0jcnRUoq87 Wzex1v6WItLN9iHb3j8cIVLLCCsoJ1Kv0wK3SWDR2MhcGBKPpbkJr7AqbMyX2Uuv6Ey/xpiH8Crqu nUvpdAVYC2s6Tcgaxx1OlY3StWvRZIsjS3MPq5QU5nPhwvkexlGO2e9Mtq/3gXxVe4byGBuKoiUio rnvFDjogi/fVjBe02rug==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nUVF0-00DPIn-7R; Wed, 16 Mar 2022 15:07:10 +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 1nUVEW-00DP6T-54 for linux-arm-kernel@lists.infradead.org; Wed, 16 Mar 2022 15:06:43 +0000 Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (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 17CF43F621 for ; Wed, 16 Mar 2022 15:06:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1647443189; bh=eRg49AH+ykBZGh1gNDRB4og+6vVHHfVxX3XDNDivrRU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=UnrIeu1NcHasPUaEFsskf+WFsk6v5psPXS2AGxJZKJS3cK5z5q8PP2nSt/oUh2SRi dJVwMB1CpBwwb4KCV7j5owHrCxTAjxqOc+WSH2DZ2fx0D8d8jsP3q8hWy60BdmSdIv PI9jy5Lzfp4Y9Lk1WMOAxgEMavSpush4WhKCzmKGOJtTIN1ojNGUrcDQmweBmAMYMQ l+4ULkc7XRCrugXG3MLpFHQovTGBHlm8M8LAGQ87ePM1h4KDSQIBqlSaPXZkwetcnU hHJuqXjF+a2q+funktCR5T0oFXcgXZ0QBRvw4+wrvut6g6Bzz9Ab0Y2Jfqk80RQMRO 5t5MclRKHaNSA== Received: by mail-wr1-f70.google.com with SMTP id e6-20020a5d4e86000000b001f045d4a962so655114wru.21 for ; Wed, 16 Mar 2022 08:06:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=eRg49AH+ykBZGh1gNDRB4og+6vVHHfVxX3XDNDivrRU=; b=YiYrvtqLiKUEclp81gGwXTincPEERJiC/eObHsr5tfaqvZWdcUcwiUewOH0Uck3umF UEHdilBnEeXvTI3Hd96Ap6HjBU9lLiOIqBkgtKExRjvk4HOK/QUi0AAXQxQEDGS8R4JT gH+4Fn+p58QPKp7nQGMzdd56nJYtcq5m1Q95RSLuBPXhYgIOv9yedHVHGPJ+hamIoEvk UXpTgyHEaLoKhor59HkU1phqvbS7+m0mkdZHSljaVbNsRvP5JhwjHlTwg/gdzuQKJw2J JoHn0HRSpLKFAhodp3040lhhgyVXUgyApDt8SAeO4AFZZriN8oe9dRWERIM7XtbWeqNG xNQg== X-Gm-Message-State: AOAM530/ep67O7zPgRvepcG0/pNbnNityw0hYqa00hd2M+/WCKfDhxpm fylTp9XWZdxqrEWsi7BkrBcCX7LbIOljlO71IH5GAj/0Ze9UootYP2wPncGWZdam9DkQDZLAhgo /dhbgdgapxLvHEfUjUjbcymAbGeygS0+5FOoYLCK4UBWuW6/2yAUe X-Received: by 2002:adf:d081:0:b0:1ef:9378:b7cc with SMTP id y1-20020adfd081000000b001ef9378b7ccmr291121wrh.407.1647443186734; Wed, 16 Mar 2022 08:06:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyDNmFS8Lm1qpNhyLNM0PQQ6xJZzdkhX7csz79UNfI868MUEUVc3OffUE9Xg2b3eJcN4JLGWg== X-Received: by 2002:adf:d081:0:b0:1ef:9378:b7cc with SMTP id y1-20020adfd081000000b001ef9378b7ccmr291084wrh.407.1647443186498; Wed, 16 Mar 2022 08:06:26 -0700 (PDT) Received: from localhost.localdomain (78-11-189-27.static.ip.netia.com.pl. [78.11.189.27]) by smtp.gmail.com with ESMTPSA id p14-20020a5d59ae000000b00203dcc87d39sm3130155wrr.54.2022.03.16.08.06.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 08:06:25 -0700 (PDT) From: Krzysztof Kozlowski To: Greg Kroah-Hartman , "Rafael J. Wysocki" Cc: Stuart Yoder , "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 , 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 , Andy Shevchenko , Krzysztof Kozlowski Subject: [PATCH v5 01/11] driver: platform: Add helper for safer setting of driver_override Date: Wed, 16 Mar 2022 16:05:23 +0100 Message-Id: <20220316150533.421349-2-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220316150533.421349-1-krzysztof.kozlowski@canonical.com> References: <20220316150533.421349-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220316_080640_492887_1D81C7EF X-CRM114-Status: GOOD ( 27.43 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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). Signed-off-by: Krzysztof Kozlowski --- drivers/base/driver.c | 56 +++++++++++++++++++++++++++++++++ drivers/base/platform.c | 28 +++-------------- include/linux/device/driver.h | 2 ++ include/linux/platform_device.h | 6 +++- 4 files changed, 67 insertions(+), 25 deletions(-) diff --git a/drivers/base/driver.c b/drivers/base/driver.c index 8c0d33e182fd..d51df6d80829 100644 --- a/drivers/base/driver.c +++ b/drivers/base/driver.c @@ -30,6 +30,62 @@ 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) +{ + const char *new, *old; + char *cp; + + if (!dev || !override || !s) + return -EINVAL; + + /* + * The stored value will be used in sysfs show callback (sysfs_emit()), + * which has a length limit of PAGE_SIZE and adds a trailing newline. + * Thus we can store one character less to avoid truncation during sysfs + * show. + */ + if (len >= (PAGE_SIZE - 1)) + return -EINVAL; + + cp = strnchr(s, len, '\n'); + if (cp) + len = cp - s; + + new = kstrndup(s, len, GFP_KERNEL); + if (!new) + return -ENOMEM; + + device_lock(dev); + old = *override; + if (cp != s) { + *override = new; + } else { + kfree(new); + *override = NULL; + } + device_unlock(dev); + + kfree(old); + + return 0; +} +EXPORT_SYMBOL_GPL(driver_set_override); + /** * driver_for_each_device - Iterator for devices bound to a driver. * @drv: Driver we're iterating. diff --git a/drivers/base/platform.c b/drivers/base/platform.c index 8cc272fd5c99..b684157b7f2f 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -1275,31 +1275,11 @@ static ssize_t driver_override_store(struct device *dev, const char *buf, size_t count) { struct platform_device *pdev = to_platform_device(dev); - char *driver_override, *old, *cp; - - /* We need to keep extra room for a newline */ - if (count >= (PAGE_SIZE - 1)) - return -EINVAL; - - driver_override = kstrndup(buf, count, GFP_KERNEL); - if (!driver_override) - return -ENOMEM; - - cp = strchr(driver_override, '\n'); - if (cp) - *cp = '\0'; - - device_lock(dev); - old = pdev->driver_override; - if (strlen(driver_override)) { - pdev->driver_override = driver_override; - } else { - kfree(driver_override); - pdev->driver_override = NULL; - } - device_unlock(dev); + int ret; - kfree(old); + ret = driver_set_override(dev, &pdev->driver_override, buf, count); + if (ret) + return ret; return count; } diff --git a/include/linux/device/driver.h b/include/linux/device/driver.h index 15e7c5e15d62..700453017e1c 100644 --- a/include/linux/device/driver.h +++ b/include/linux/device/driver.h @@ -151,6 +151,8 @@ extern int __must_check driver_create_file(struct device_driver *driver, extern void driver_remove_file(struct device_driver *driver, const struct driver_attribute *attr); +int driver_set_override(struct device *dev, const char **override, + const char *s, size_t len); extern int __must_check driver_for_each_device(struct device_driver *drv, struct device *start, void *data, diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h index 7c96f169d274..582d83ed9a91 100644 --- a/include/linux/platform_device.h +++ b/include/linux/platform_device.h @@ -31,7 +31,11 @@ struct platform_device { struct resource *resource; const struct platform_device_id *id_entry; - char *driver_override; /* Driver name to force a match */ + /* + * Driver name to force a match. Do not set directly, because core + * frees it. Use driver_set_override() to set or clear it. + */ + const char *driver_override; /* MFD cell pointer */ struct mfd_cell *mfd_cell; From patchwork Wed Mar 16 15:05:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 12782769 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 5FDF6C433EF for ; Wed, 16 Mar 2022 15:08:09 +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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=TkfOW8ZE8Vg/NULLbxrT4SgldMk0a1Wl/KFmhMEoZgA=; b=aW1QrBTjZ8JQWf pfJx77fS6U4JvXUtz9QpkZ5swv2R6XGX1N8lBKLm6MDIRvWUMDA1xm6IrAUso0qC18ozBCx6aP12m LcMoFUZ56GBAvJWjWHo6doq1hNrPthZyfyWLud3hasoX/uh84f+ofGXZzJNQ9WFnn0j7Prv9B1naD vkSPUgFMmLjdRuYZlj73F23xYhK3yGdfmx8sgCI4ITHKL2GqzzZrbc2AC7DFS2CXVIREEN3Q1dgDu LePZNR/lnZ0VkppFLMrJcEo6Rz7kbGsvznQIdRBoMuP/CUL5Gu74kM0/QZ9udiaRc4nUnoCjTeBoc DE2Nq59jB64rl1Qcw+RQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nUVEZ-00DP7t-JQ; Wed, 16 Mar 2022 15:06:43 +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 1nUVEW-00DP6V-52 for linux-arm-kernel@lists.infradead.org; Wed, 16 Mar 2022 15:06:41 +0000 Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (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 B9D953F62D for ; Wed, 16 Mar 2022 15:06:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1647443191; bh=LxSp3r31kTKgdYVIAcfNeHGsMIq2YcJzJF2DRNz1kEo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=slsseQQsKbUN4GEr0QRJ7EpYsghZT45B9D7j2htUQ+XbZswCRpBHLyKCpAA1T13ah uvb5DJ7zr3ce1LF6SWwus9XHfGI3eyhh39y1oCcV2jgM2mqAlvFZrDK4tX0f/h+dgm SIrq+5gVG2F8mUIhptqtFoCN5/tbjQYcQJpSs4XMUnHVzGcWlj7rU43my0Ywj1Po00 mpbbG0vF75zAWbFe/rbW2zPHrx1EaJsOjgvE7yZUeFztihj4Ebi+8lXySAaVX+0n3Y uphcp90XM/YjOcqPCJUlyxAnkBYEIP8Ra7QJs9vuzCf++2QO4FwfgIg5IlUFC7t9Zh YTu5cj4Ce6Now== Received: by mail-wr1-f71.google.com with SMTP id a5-20020adfdd05000000b001f023fe32ffso652228wrm.18 for ; Wed, 16 Mar 2022 08:06:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LxSp3r31kTKgdYVIAcfNeHGsMIq2YcJzJF2DRNz1kEo=; b=aX2nMruSNnrExuBPvifWFMs/JoTI8CCMHvVmwt+2SMkRhHtJKU2u3gpe9niww1BSlJ W/N4MfY3R8BrrNETsB4V4f4sy2Zx2xDiT27+vmT0h9zTRpQzzC8CTrK8619htvGmV1Y4 gPBKaZwDll4K9MhUhe/SmEyugk1DahbqH3QILp+prU4P+JCICXlhlqFSgOg2pFcI73+t u3XdT1YsddQ5/gQWDbCT6YqLo8AGUqpUDWji1frBG8Bm5YcyvnhA8OLnC5cwAr+dqHi3 yQ64u1puH/Q5fMAVsRiswx5fvdHCThQEk7E/wt1ijlyoeld6vUWBJEI/zyqCcJjIpqdH Rn/w== X-Gm-Message-State: AOAM532aRZdeJoHt4FrzU8a12u7jFnU7Tm1wSGvwLHqgyR8IABoKn3if DEARXyw+mLyzOV7/Vt8fUToUAYbw8w/viKxchw/H/eB18m9ekDmYmR50KHA1kS2ji8V0/mXSdkg vMSThpUfbX7oF67MEXhBzVAqGULZIvR9KrXxeORDXsQVBqbloBJBp X-Received: by 2002:a7b:c5d0:0:b0:355:482a:6f44 with SMTP id n16-20020a7bc5d0000000b00355482a6f44mr130539wmk.58.1647443190445; Wed, 16 Mar 2022 08:06:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzdXtZV1RU4W+D/CxNpLgNYuPn/wREOODQjEf3w6MZJYByf0aAfpBebBFJL0kKpQw0vNQJhuw== X-Received: by 2002:a7b:c5d0:0:b0:355:482a:6f44 with SMTP id n16-20020a7bc5d0000000b00355482a6f44mr130503wmk.58.1647443190091; Wed, 16 Mar 2022 08:06:30 -0700 (PDT) Received: from localhost.localdomain (78-11-189-27.static.ip.netia.com.pl. [78.11.189.27]) by smtp.gmail.com with ESMTPSA id p14-20020a5d59ae000000b00203dcc87d39sm3130155wrr.54.2022.03.16.08.06.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 08:06:28 -0700 (PDT) From: Krzysztof Kozlowski To: Greg Kroah-Hartman , "Rafael J. Wysocki" Cc: Stuart Yoder , "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 , 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 , Andy Shevchenko , Krzysztof Kozlowski Subject: [PATCH v5 02/11] amba: Use driver_set_override() instead of open-coding Date: Wed, 16 Mar 2022 16:05:24 +0100 Message-Id: <20220316150533.421349-3-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220316150533.421349-1-krzysztof.kozlowski@canonical.com> References: <20220316150533.421349-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220316_080640_493007_2F03F4E8 X-CRM114-Status: GOOD ( 18.37 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Use a helper to set driver_override to reduce the amount of duplicated code. Make the driver_override field const char, because it is not modified by the core and it matches other subsystems. Signed-off-by: Krzysztof Kozlowski --- drivers/amba/bus.c | 28 ++++------------------------ include/linux/amba/bus.h | 6 +++++- 2 files changed, 9 insertions(+), 25 deletions(-) diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c index d3bd14aaabf6..f3d26d698b77 100644 --- a/drivers/amba/bus.c +++ b/drivers/amba/bus.c @@ -94,31 +94,11 @@ static ssize_t driver_override_store(struct device *_dev, const char *buf, size_t count) { struct amba_device *dev = to_amba_device(_dev); - char *driver_override, *old, *cp; - - /* We need to keep extra room for a newline */ - if (count >= (PAGE_SIZE - 1)) - return -EINVAL; - - driver_override = kstrndup(buf, count, GFP_KERNEL); - if (!driver_override) - return -ENOMEM; - - cp = strchr(driver_override, '\n'); - if (cp) - *cp = '\0'; - - device_lock(_dev); - old = dev->driver_override; - if (strlen(driver_override)) { - dev->driver_override = driver_override; - } else { - kfree(driver_override); - dev->driver_override = NULL; - } - device_unlock(_dev); + int ret; - kfree(old); + ret = driver_set_override(_dev, &dev->driver_override, buf, count); + if (ret) + return ret; return count; } diff --git a/include/linux/amba/bus.h b/include/linux/amba/bus.h index 6562f543c3e0..93799a72ff82 100644 --- a/include/linux/amba/bus.h +++ b/include/linux/amba/bus.h @@ -70,7 +70,11 @@ struct amba_device { unsigned int cid; struct amba_cs_uci_id uci; unsigned int irq[AMBA_NR_IRQS]; - char *driver_override; + /* + * Driver name to force a match. Do not set directly, because core + * frees it. Use driver_set_override() to set or clear it. + */ + const char *driver_override; }; struct amba_driver { From patchwork Wed Mar 16 15:05:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 12782773 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 6B8F1C433F5 for ; Wed, 16 Mar 2022 15:08:59 +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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=LstuRjR69DFcrPIJmdWh0CaU3es9VmLGJ8F6kTrJQnI=; b=2FHnTvF2c4+Bkh l2JmvfzuZtFwjzZGnU6QSv7cQfOVl4Tc1lM56wbBTyz2Pptk4+lM8x4Qwz3JkRY8RsUeoibD5VSqC H2Zzjs/a64JoPBY3s5kv0zOoT3gm34VqOHH3jAo635kRQcREcMQLDA+Sws5b4MOF/1amf7zuDjj18 nJ5OUB2a3Fc9SttOFl+Edy2kNZQid2z3JLki28qaznis2gFHVaSi5vwcAOmm0MYkzutwWE2uDR1hL kd8bqIWgbfnLNZD10oqpUsqGGAzIdy4+uO5uA4fPX1BiFQ6KuTH9XekCCjcRfZ0uxF3+xWVmrHBjj wDrRYqnx7qoQw8jeNPGA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nUVFP-00DPSD-D4; Wed, 16 Mar 2022 15:07:35 +0000 Received: from smtp-relay-internal-1.canonical.com ([185.125.188.123]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nUVEe-00DP9E-02 for linux-arm-kernel@lists.infradead.org; Wed, 16 Mar 2022 15:06:50 +0000 Received: from mail-lj1-f198.google.com (mail-lj1-f198.google.com [209.85.208.198]) (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-1.canonical.com (Postfix) with ESMTPS id 2B0BA3FFD9 for ; Wed, 16 Mar 2022 15:06:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1647443206; bh=BsP1eItj+J1d4aDzpqEMBIF5j1znYVUHQj+VHIPIFgg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=JIa8/hazMwGOABZ85wT4M5sDJs3EzPKKXBj5Q7yOXlAYEUcGT9kwsVm2qpSoeMdt/ gBSU5gMyUCAhGWnJ7ehO6V3/DtAYaNNu7uH40h1m4oisjepzxNW5Zx6HrwIMbbDk18 OesbyJaCadgweVPhGKHxDBHBoZVdFHfwMziMIJTo8IL65zeCbU025GLwZ6BP4Yzs/r oVOc4FkvB7W8YtUVaiIMnOGNeYsBh0Zf9CNj1tTJOVppmBHGsKjf22SuF4g4cqJ2vh p6Ngc1IzxgC4fkesL+e4GhhXV5umsUsLDeuH/zSCPLL2cLd8f/M5tTZ0WGl6CvAA8I rdddI+jKDrwmw== Received: by mail-lj1-f198.google.com with SMTP id v9-20020a2e9909000000b00247ecf60956so1022525lji.12 for ; Wed, 16 Mar 2022 08:06:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BsP1eItj+J1d4aDzpqEMBIF5j1znYVUHQj+VHIPIFgg=; b=QQYy2CilJwvucou3ua3GhZFfqkBrJf0AhpTEjq/ks6REOGoV7VC+BqI5Eb3hBbqPYb bOoFfPBTf2GExCjhgrIUWzXWpSEB+DaRbDbl0vVP+YMWfLm8nblSs2+NMBfeyuL4p7mI duRiY6RZH9leRtY5qH18ovF7lpzyb4bwqJzMjgCtxU1ASXjMBilAf6UY31ORrllpSqbW ZojZJqdgNJwdcCOGnJgijaa7VzLb9ujhumNsyeadnV14tTn6C9Vb810Pv0uCHEdv9PIs ar5/fF/bkhYdWPY8HH3Aw0r+M2bUYGJ8RDuMQHSSW7to+M1Mx+tniTyPiJdfDVtmdaWZ lHqQ== X-Gm-Message-State: AOAM5332tm7IsM5vcM0Z+iu6vP2Qk9o3rbT3rNt2zniSSdzEL4NJkuMZ AKV6FBqJwr0EojTBD4x2e/LQOsEXMVzPs7XZ0E/2O5tOB6d+Im6vYWVbDuQqvFuLypo1RJvJIls SkJHGgpa38oolqzodmBx8uDOsAPCx2EdYBp7HXfP3skZknf0X/NFj X-Received: by 2002:adf:f68d:0:b0:203:7b96:a7ff with SMTP id v13-20020adff68d000000b002037b96a7ffmr326846wrp.101.1647443193785; Wed, 16 Mar 2022 08:06:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxoarwZUHPsM12itXV7mRUexTXGgAuLA6KWe3K/HjtbGdnXbQ8PTTCIoN4L2QaZn0F+apvl9w== X-Received: by 2002:adf:f68d:0:b0:203:7b96:a7ff with SMTP id v13-20020adff68d000000b002037b96a7ffmr326805wrp.101.1647443193616; Wed, 16 Mar 2022 08:06:33 -0700 (PDT) Received: from localhost.localdomain (78-11-189-27.static.ip.netia.com.pl. [78.11.189.27]) by smtp.gmail.com with ESMTPSA id p14-20020a5d59ae000000b00203dcc87d39sm3130155wrr.54.2022.03.16.08.06.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 08:06:32 -0700 (PDT) From: Krzysztof Kozlowski To: Greg Kroah-Hartman , "Rafael J. Wysocki" Cc: Stuart Yoder , "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 , 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 , Andy Shevchenko , Krzysztof Kozlowski Subject: [PATCH v5 03/11] fsl-mc: Use driver_set_override() instead of open-coding Date: Wed, 16 Mar 2022 16:05:25 +0100 Message-Id: <20220316150533.421349-4-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220316150533.421349-1-krzysztof.kozlowski@canonical.com> References: <20220316150533.421349-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220316_080648_198923_3CA68EFC X-CRM114-Status: GOOD ( 17.37 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Use a helper to set driver_override to reduce the amount of duplicated code. Make the driver_override field const char, because it is not modified by the core and it matches other subsystems. Signed-off-by: Krzysztof Kozlowski --- drivers/bus/fsl-mc/fsl-mc-bus.c | 25 ++++--------------------- include/linux/fsl/mc.h | 6 ++++-- 2 files changed, 8 insertions(+), 23 deletions(-) diff --git a/drivers/bus/fsl-mc/fsl-mc-bus.c b/drivers/bus/fsl-mc/fsl-mc-bus.c index 8fd4a356a86e..ba01c7f4de92 100644 --- a/drivers/bus/fsl-mc/fsl-mc-bus.c +++ b/drivers/bus/fsl-mc/fsl-mc-bus.c @@ -166,31 +166,14 @@ static ssize_t driver_override_store(struct device *dev, const char *buf, size_t count) { struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev); - char *driver_override, *old = mc_dev->driver_override; - char *cp; + int ret; if (WARN_ON(dev->bus != &fsl_mc_bus_type)) return -EINVAL; - if (count >= (PAGE_SIZE - 1)) - return -EINVAL; - - driver_override = kstrndup(buf, count, GFP_KERNEL); - if (!driver_override) - return -ENOMEM; - - cp = strchr(driver_override, '\n'); - if (cp) - *cp = '\0'; - - if (strlen(driver_override)) { - mc_dev->driver_override = driver_override; - } else { - kfree(driver_override); - mc_dev->driver_override = NULL; - } - - kfree(old); + ret = driver_set_override(dev, &mc_dev->driver_override, buf, count); + if (ret) + return ret; return count; } diff --git a/include/linux/fsl/mc.h b/include/linux/fsl/mc.h index 7b6c42bfb660..7a87ab9eba99 100644 --- a/include/linux/fsl/mc.h +++ b/include/linux/fsl/mc.h @@ -170,7 +170,9 @@ struct fsl_mc_obj_desc { * @regions: pointer to array of MMIO region entries * @irqs: pointer to array of pointers to interrupts allocated to this device * @resource: generic resource associated with this MC object device, if any. - * @driver_override: driver name to force a match + * @driver_override: driver name to force a match; do not set directly, + * because core frees it; use driver_set_override() to + * set or clear it. * * Generic device object for MC object devices that are "attached" to a * MC bus. @@ -204,7 +206,7 @@ struct fsl_mc_device { struct fsl_mc_device_irq **irqs; struct fsl_mc_resource *resource; struct device_link *consumer_link; - char *driver_override; + const char *driver_override; }; #define to_fsl_mc_device(_dev) \ From patchwork Wed Mar 16 15:05:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 12782836 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 6B94FC433F5 for ; Wed, 16 Mar 2022 15:09:33 +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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=WdOhad+uFjOcKka35AXbODg5EV3rnzjntSe6snrv/kM=; b=sHXKoVdzEAMYxY fcAWC/Fxd+J1v2ZcZyOX/476cwu6PQKDLr7EeR6lP8iWOJ8aZGIMKSZxYliHBrNJo5UlYlzjfyAcg 1qB6aPBUaznkuPmwVR6KFu+2pynFlBLHj4zJpqWr2qTAl1vPWDGS9aUDPVQjBOPKYKgoAnfN+h11f 7GJINUakDzufNcFQaT7hFtwxOyIwP0iXsh0vLPpPTwxNPfvLaDoAHZtl6mIfGT3FBLsdBnm/qJaGD wH7ypRi/agbdNa2A7bi21jcdP62RE9rBFFuTuV4jbAJ2drrTRupmGM+1hQggAwmWKcAQbKc9CExth oz3yW7/QDSkDBNGi/3Kw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nUVFg-00DPZM-UN; Wed, 16 Mar 2022 15:07:54 +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 1nUVEg-00DPAW-R9 for linux-arm-kernel@lists.infradead.org; Wed, 16 Mar 2022 15:06:52 +0000 Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) (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 8832D3F1AF for ; Wed, 16 Mar 2022 15:06:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1647443209; bh=qe4dhnprNWM6uzn5SGQYSUaT3EAa0OIFZFVGuX4NqAE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=vE57SmuIgdMCDxbOpz0yHOe4anylRKMJQPNUqWxC8xJkqt8EiR44U2uxbhyHSQKe0 LEIaEFxmt+a1LaCdre5kebd0QnpnW4AhDXsaU4+RJFSbomUfceYoEMunpRILSL3Esd +PxAxRHJ4wFfkAsgSPG6dBP28ArQeQZE+hcLoG/Lbm4y1R/eqa31DPkhMQVEKQCj/p eHCWpgRbe6APd7tSz4kkmoY+x/lMB2ViNQb3O6O4GpKeSizsD22HIvIottk1Tat9jG Z49ZlI5Owgq9ga+B7WrfFOTOzek8a/XuKpQzAUejTSMZ8GpR3GlrUwoL7y+CfkQoM3 dm7Vz7f3ET1aA== Received: by mail-ej1-f69.google.com with SMTP id i14-20020a17090639ce00b006dabe6a112fso1309153eje.13 for ; Wed, 16 Mar 2022 08:06:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qe4dhnprNWM6uzn5SGQYSUaT3EAa0OIFZFVGuX4NqAE=; b=7hCcf/Ym7wvdvCuw+ppFMH2kQulztrLyUeMQHrbWj4DgfksuYXRBik5wTZsq31AI1D ZoeYxmV2HSSwiCU205EPs/waGex/VTR3CjnsDI9yghyVE6MFFkyV8kgscDQxoEunmB7j 1ZH31y2X1RLy7/Escs/RrK14T9Vs5QbKwdMBiz8Hd6uudMvMk65eGdjrjcTtIk0Hy7Io ZBaa++WGoeZYCrE6D7+gauzafeqs6aVF/uOWGXsVs26LlRdLEopH6PNr8ydT7W5uKYxE jbGUR4bzJzoKe8sa1x40tPTPGmtJcogO8NIz9n/1+hPLNV7YCyocVblskHID92O9anhR IMjg== X-Gm-Message-State: AOAM530WrEm7zYJfp1lqBFr8PO7HAFkVctzRatxbWsJht6ky+w2lJg2W 9DxpnEhQEKix2WUMjBXhEEy0rnS28l77qInHD4mhP4DK78+jsRekdJi60TOKJFRGU4/4waprnm2 VAULiNLLJ7k/lxMqFcVfgeGHBFkMeV1RlGFbMA4u4rrBru4HSRFa/ X-Received: by 2002:adf:f48d:0:b0:1ed:e2d7:d5e0 with SMTP id l13-20020adff48d000000b001ede2d7d5e0mr339346wro.252.1647443196957; Wed, 16 Mar 2022 08:06:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwLiBCbgm6QRK3G0rpLKvHnouae5z5SEdfWjFsLkOL7izSJ06dvAGkwNICqtwmEJDwxDDgSbw== X-Received: by 2002:adf:f48d:0:b0:1ed:e2d7:d5e0 with SMTP id l13-20020adff48d000000b001ede2d7d5e0mr339317wro.252.1647443196762; Wed, 16 Mar 2022 08:06:36 -0700 (PDT) Received: from localhost.localdomain (78-11-189-27.static.ip.netia.com.pl. [78.11.189.27]) by smtp.gmail.com with ESMTPSA id p14-20020a5d59ae000000b00203dcc87d39sm3130155wrr.54.2022.03.16.08.06.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 08:06:35 -0700 (PDT) From: Krzysztof Kozlowski To: Greg Kroah-Hartman , "Rafael J. Wysocki" Cc: Stuart Yoder , "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 , 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 , Andy Shevchenko , Krzysztof Kozlowski , Michael Kelley Subject: [PATCH v5 04/11] hv: Use driver_set_override() instead of open-coding Date: Wed, 16 Mar 2022 16:05:26 +0100 Message-Id: <20220316150533.421349-5-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220316150533.421349-1-krzysztof.kozlowski@canonical.com> References: <20220316150533.421349-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220316_080651_049687_F382320B X-CRM114-Status: GOOD ( 17.99 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Use a helper to set driver_override to the reduce amount of duplicated code. Make the driver_override field const char, because it is not modified by the core and it matches other subsystems. Signed-off-by: Krzysztof Kozlowski Reviewed-by: Michael Kelley --- drivers/hv/vmbus_drv.c | 28 ++++------------------------ include/linux/hyperv.h | 6 +++++- 2 files changed, 9 insertions(+), 25 deletions(-) diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c index 60ee8b329f9e..66213ce5579d 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c @@ -575,31 +575,11 @@ static ssize_t driver_override_store(struct device *dev, const char *buf, size_t count) { struct hv_device *hv_dev = device_to_hv_device(dev); - char *driver_override, *old, *cp; - - /* We need to keep extra room for a newline */ - if (count >= (PAGE_SIZE - 1)) - return -EINVAL; - - driver_override = kstrndup(buf, count, GFP_KERNEL); - if (!driver_override) - return -ENOMEM; - - cp = strchr(driver_override, '\n'); - if (cp) - *cp = '\0'; - - device_lock(dev); - old = hv_dev->driver_override; - if (strlen(driver_override)) { - hv_dev->driver_override = driver_override; - } else { - kfree(driver_override); - hv_dev->driver_override = NULL; - } - device_unlock(dev); + int ret; - kfree(old); + ret = driver_set_override(dev, &hv_dev->driver_override, buf, count); + if (ret) + return ret; return count; } diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h index fe2e0179ed51..12e2336b23b7 100644 --- a/include/linux/hyperv.h +++ b/include/linux/hyperv.h @@ -1257,7 +1257,11 @@ struct hv_device { u16 device_id; struct device device; - char *driver_override; /* Driver name to force a match */ + /* + * Driver name to force a match. Do not set directly, because core + * frees it. Use driver_set_override() to set or clear it. + */ + const char *driver_override; struct vmbus_channel *channel; struct kset *channels_kset; From patchwork Wed Mar 16 15:05:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 12782837 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 722DEC433FE for ; Wed, 16 Mar 2022 15:09:52 +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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=QbpvxWpSrxRjYl9kN7E94C3auatMaOT7CkCusG5K9Es=; b=bC+c1hCFk2fCVh O0fhs2I9yeVglsJN4TZABn8IhyQeRqQUNV0O52esPLRwP3p4lbHJo6nGzgoB5stspUw3gIwcG/v0M uqqD2dtADr9ytgfD5gwUXdurkB+lAbExdouDMspIPHtx7pzTa60HeHD/Ou2S4620/S0mb6cnzy6+I cf8H2qKqwLnXJv7TXwqZc2RysyAWEGJQ1jrOGII2YsPxBdB7GnOh2yEM4saEvVc6NWkXn3zzAR4Cg rxoSzUygQ1NboEHlQkz6UcN73RD9yotOQfXbJbfa+93kCTZdgSDMrRqgNhBV3GPCuueJyy8tccQ4h AFAHNkVOkJ47uRNf8HdQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nUVG0-00DPjZ-2A; Wed, 16 Mar 2022 15:08:12 +0000 Received: from smtp-relay-internal-1.canonical.com ([185.125.188.123]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nUVEj-00DPBv-1K for linux-arm-kernel@lists.infradead.org; Wed, 16 Mar 2022 15:06:54 +0000 Received: from mail-lj1-f197.google.com (mail-lj1-f197.google.com [209.85.208.197]) (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-1.canonical.com (Postfix) with ESMTPS id C502B3F4CC for ; Wed, 16 Mar 2022 15:06:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1647443211; bh=JNKVE+3JexqhZeL95jpZ7AxMh5V3BiZd1u/ZcabQDj4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ZDYVsdhzekWMwPPkB5MTx7wYc7GzLqdZuCTeR1xXWl2OuCDYjmCaUj4t1d4EZU0pK gMt6+G6dpyh8C1c1T1sBtXPLkDfIwZYUoG4pEYyCWebSWoRQQA0S3grju3YcFkFfA8 Oy/1fyEz4b3NNXQn7nDpQUaiUtOvIoeGtq4dhMOXMQu8G/lbUsIglk4FJqd8/XMEZe af6lK/wZZGErlZcup0PYKcyEFk/NJR2TqDq7RLSgjmsJartr3FuA3LMDqEiSjHghXD ff5PbKDM7ACD4OubQx6rP3X/rffNQYzq0va4kIJWxUkizp7FTIiLqHY1pHZjunqrlS RIcchHiAsL71A== Received: by mail-lj1-f197.google.com with SMTP id f21-20020a2e9515000000b00247e2f244easo1013193ljh.19 for ; Wed, 16 Mar 2022 08:06:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JNKVE+3JexqhZeL95jpZ7AxMh5V3BiZd1u/ZcabQDj4=; b=nGFCWIyeqs5JY4Fe29nl6Nq7l9cPD/K13C1YUVv0MsqWNJklFj+Os9ct1Eqs9aL7Us U+3iKE/srUjMW1radqJGbiVtOTUfT+ksPdD/hyRt7a87W3FQ3cV2iUMR4ORBRgrHXKCz gFHHoKjsv0Cgfpj+GjU6DHE1z9B+jDw55JRHU6MVbalBNme7rotV8/iACacvNmVm3FUR jK+wkxoF/0V+6Tr2Rk88mb9KJUYR8PrD+GGoxloBaXyqhYqGySM2cq3T4uCDYmPuceaZ mghZkaPkjVuD045t/AmlLqHzKoANHqg5iPyBHTH4BD2gLrorrLScGY8ha2KxPECjdtVg O+xg== X-Gm-Message-State: AOAM531WhxYeQKaLgUWyGrIIz8MbqXjjUv+FECDAzERGBhZmoNTlWg/2 7pHHRuo09uq2UZR05UwoX0YuorCZsfIws6wL1A40fY9MN0aZ3z9xxyEyFKoPHiZ8RR07nDfIY4F l/sYItbbSE37M9JlaN+24SDLCo1ypJX5unrxIf3dvM93IwKHjPRWm X-Received: by 2002:adf:e6c7:0:b0:1ed:9f7c:c99e with SMTP id y7-20020adfe6c7000000b001ed9f7cc99emr338962wrm.0.1647443200062; Wed, 16 Mar 2022 08:06:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyCUhxAKawe3MPuphaitMx3nXTnkxh9V6g1RJgrcVXBEtRF7kgts/Kf4MtPXL4nFMNuuGjZig== X-Received: by 2002:adf:e6c7:0:b0:1ed:9f7c:c99e with SMTP id y7-20020adfe6c7000000b001ed9f7cc99emr338940wrm.0.1647443199883; Wed, 16 Mar 2022 08:06:39 -0700 (PDT) Received: from localhost.localdomain (78-11-189-27.static.ip.netia.com.pl. [78.11.189.27]) by smtp.gmail.com with ESMTPSA id p14-20020a5d59ae000000b00203dcc87d39sm3130155wrr.54.2022.03.16.08.06.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 08:06:38 -0700 (PDT) From: Krzysztof Kozlowski To: Greg Kroah-Hartman , "Rafael J. Wysocki" Cc: Stuart Yoder , "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 , 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 , Andy Shevchenko , Krzysztof Kozlowski Subject: [PATCH v5 05/11] PCI: Use driver_set_override() instead of open-coding Date: Wed, 16 Mar 2022 16:05:27 +0100 Message-Id: <20220316150533.421349-6-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220316150533.421349-1-krzysztof.kozlowski@canonical.com> References: <20220316150533.421349-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220316_080653_275880_A3EA500B X-CRM114-Status: GOOD ( 19.29 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Use a helper to set driver_override to the reduce amount of duplicated code. Make the driver_override field const char, because it is not modified by the core and it matches other subsystems. Signed-off-by: Krzysztof Kozlowski Acked-by: Bjorn Helgaas Reviewed-by: Andy Shevchenko --- drivers/pci/pci-sysfs.c | 28 ++++------------------------ include/linux/pci.h | 6 +++++- 2 files changed, 9 insertions(+), 25 deletions(-) diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index 602f0fb0b007..5c42965c32c2 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -567,31 +567,11 @@ static ssize_t driver_override_store(struct device *dev, const char *buf, size_t count) { struct pci_dev *pdev = to_pci_dev(dev); - char *driver_override, *old, *cp; - - /* We need to keep extra room for a newline */ - if (count >= (PAGE_SIZE - 1)) - return -EINVAL; - - driver_override = kstrndup(buf, count, GFP_KERNEL); - if (!driver_override) - return -ENOMEM; - - cp = strchr(driver_override, '\n'); - if (cp) - *cp = '\0'; - - device_lock(dev); - old = pdev->driver_override; - if (strlen(driver_override)) { - pdev->driver_override = driver_override; - } else { - kfree(driver_override); - pdev->driver_override = NULL; - } - device_unlock(dev); + int ret; - kfree(old); + ret = driver_set_override(dev, &pdev->driver_override, buf, count); + if (ret) + return ret; return count; } diff --git a/include/linux/pci.h b/include/linux/pci.h index b957eeb89c7a..5ecbb845aa21 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -516,7 +516,11 @@ struct pci_dev { u16 acs_cap; /* ACS Capability offset */ phys_addr_t rom; /* Physical address if not from BAR */ size_t romlen; /* Length if not from BAR */ - char *driver_override; /* Driver name to force a match */ + /* + * Driver name to force a match. Do not set directly, because core + * frees it. Use driver_set_override() to set or clear it. + */ + const char *driver_override; unsigned long priv_flags; /* Private flags for the PCI driver */ From patchwork Wed Mar 16 15:05:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 12782772 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 AAAF6C433F5 for ; Wed, 16 Mar 2022 15:08:56 +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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=OBndw7EMlpyd0c7XqpEFnAF82ncArc7vgVYgs/qtt1s=; b=vwHJgxAYRqPvmJ uRH2wSVfSCVAIf0T3C5rV6r3R2kOHOr2avgBUcqri6EfsTrc5E4cpYEMbmQSHKW6r+CuQuf8KVV40 udzAdDZKTEFh71nI5JW7VVk3jJj0kts2hv72KkZtEsZ+EGXpsxZjB4FjjC1qP2fioWzL/THZz7Ru1 gEO6cjLrdg9uqvZyspJl6cJblpiyi6blXYmpjex9wextiOeFMYkaNqq75YgZZqVS7mG/JtD4AkUra MocoAhwt9MZ5SPex6UU5s46bsTslC17Bw5kLTyVUzW3JHrZxIOSet2vdhc/x63i49xkqWkcTnuaVE kZY/vR0IClW47YnbnuHQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nUVFC-00DPO5-Oy; Wed, 16 Mar 2022 15:07:23 +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 1nUVEd-00DP8n-Bi for linux-arm-kernel@lists.infradead.org; Wed, 16 Mar 2022 15:06:48 +0000 Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (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 94F313F312 for ; Wed, 16 Mar 2022 15:06:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1647443204; bh=QAEyo1xXNWnC/wTobDlvVW3kuxucr7Y+nryukeY/7zA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=jG0pbWhNnsvCLavoQQbQgKLfJAHOfNO1INVivJWaFWfXo/d4EOmRwljZ3Wl5zK25R lLPH7nZdXg9bD3dmM4b4g7QCPaXghLdIg76+/rdsBgf4Rpju/YDOJP9ijhtkybSo5R ODUoe2S8QY0Da082HZZQpCVEU2Fxlx5FYHufMA0nnA7AQ47TO7x9bgxbs+xXtTtSwf swfgMo5OsazM/e6A8Bmh6JdaIkTYANf5ix15yS1/1xosMUJPS5q6NLLOriSWypARGW M7dwaHfMoEI1qgB+9YDdbHJgcavZHSAP2BzxhbH1vtAnjQBGIwDCXKEKrdGw6msTqr WjEDXdbkBz8ow== Received: by mail-wr1-f70.google.com with SMTP id d17-20020adfc3d1000000b00203e2ff73a6so448036wrg.8 for ; Wed, 16 Mar 2022 08:06:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QAEyo1xXNWnC/wTobDlvVW3kuxucr7Y+nryukeY/7zA=; b=i0o6zuC4nkcyWm0OALsNHCee+Wjqt0x8xmeYHc4v5GmRZAeESn5xrqEapqz06/RxuM p+SM/Ipm0mhhu1ToijiJkFY8yDfLR5S0Dzrb/efYD7MmztT5SAn0pSYRHAydfbItQjgD SvoiXWlrPk06cK8Suck+by9gYL9ojjim+01rSPdU3oEjEJ5s6ASz/sr1nFALFOkdd0uA bXRr5mhXjqHkitcL+zrpMdF7TTUHovWfnJeqw+LCfD/VpRJMvxM2J/e2CS+dV5WarRIb NFJaBqcQ60HYuEyS4KgjZvPFe+TvmKYjXiTbfSxGr+XppNU1F3XqO0muQbwoeFUloLPY Z+Rw== X-Gm-Message-State: AOAM531VjziLmKyCN7o0y/TFc1Y455PTGcV8ST4VnudHs/UwR77R+3sE UR3GD5geWm9KRZF3MjeiCaHR9L/AxcG8wg2o5q1kyBAdApSdQXt48KKJlTBaqI3Usq84CK1ULR4 JJrDhc/O7mFjZSBKUgDrmxWsPBvd8bWMUUpXESn2OEvhm7dV0jau8 X-Received: by 2002:a5d:55c5:0:b0:1f0:7672:637d with SMTP id i5-20020a5d55c5000000b001f07672637dmr349039wrw.170.1647443202242; Wed, 16 Mar 2022 08:06:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxweeXNXzqSiK6jLHKTzxTuSJXVd/nxHPvdpHWEAERfetg3Sykd8n3TukHieLMV78+GWu3x+Q== X-Received: by 2002:a5d:55c5:0:b0:1f0:7672:637d with SMTP id i5-20020a5d55c5000000b001f07672637dmr349028wrw.170.1647443202062; Wed, 16 Mar 2022 08:06:42 -0700 (PDT) Received: from localhost.localdomain (78-11-189-27.static.ip.netia.com.pl. [78.11.189.27]) by smtp.gmail.com with ESMTPSA id p14-20020a5d59ae000000b00203dcc87d39sm3130155wrr.54.2022.03.16.08.06.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 08:06:41 -0700 (PDT) From: Krzysztof Kozlowski To: Greg Kroah-Hartman , "Rafael J. Wysocki" Cc: Stuart Yoder , "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 , 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 , Andy Shevchenko , Krzysztof Kozlowski Subject: [PATCH v5 06/11] s390/cio: Use driver_set_override() instead of open-coding Date: Wed, 16 Mar 2022 16:05:28 +0100 Message-Id: <20220316150533.421349-7-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220316150533.421349-1-krzysztof.kozlowski@canonical.com> References: <20220316150533.421349-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220316_080647_558013_A20144BF X-CRM114-Status: GOOD ( 17.85 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Use a helper to set driver_override to the reduce amount of duplicated code. Make the driver_override field const char, because it is not modified by the core and it matches other subsystems. Signed-off-by: Krzysztof Kozlowski Acked-by: Vineeth Vijayan --- drivers/s390/cio/cio.h | 6 +++++- drivers/s390/cio/css.c | 28 ++++------------------------ 2 files changed, 9 insertions(+), 25 deletions(-) diff --git a/drivers/s390/cio/cio.h b/drivers/s390/cio/cio.h index 1cb9daf9c645..fa8df50bb49e 100644 --- a/drivers/s390/cio/cio.h +++ b/drivers/s390/cio/cio.h @@ -103,7 +103,11 @@ struct subchannel { struct work_struct todo_work; struct schib_config config; u64 dma_mask; - char *driver_override; /* Driver name to force a match */ + /* + * Driver name to force a match. Do not set directly, because core + * frees it. Use driver_set_override() to set or clear it. + */ + const char *driver_override; } __attribute__ ((aligned(8))); DECLARE_PER_CPU_ALIGNED(struct irb, cio_irb); diff --git a/drivers/s390/cio/css.c b/drivers/s390/cio/css.c index fa8293335077..913b6ddd040b 100644 --- a/drivers/s390/cio/css.c +++ b/drivers/s390/cio/css.c @@ -338,31 +338,11 @@ static ssize_t driver_override_store(struct device *dev, const char *buf, size_t count) { struct subchannel *sch = to_subchannel(dev); - char *driver_override, *old, *cp; - - /* We need to keep extra room for a newline */ - if (count >= (PAGE_SIZE - 1)) - return -EINVAL; - - driver_override = kstrndup(buf, count, GFP_KERNEL); - if (!driver_override) - return -ENOMEM; - - cp = strchr(driver_override, '\n'); - if (cp) - *cp = '\0'; - - device_lock(dev); - old = sch->driver_override; - if (strlen(driver_override)) { - sch->driver_override = driver_override; - } else { - kfree(driver_override); - sch->driver_override = NULL; - } - device_unlock(dev); + int ret; - kfree(old); + ret = driver_set_override(dev, &sch->driver_override, buf, count); + if (ret) + return ret; return count; } From patchwork Wed Mar 16 15:07:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 12782838 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 D532CC433EF for ; Wed, 16 Mar 2022 15:10:56 +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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=EwTnAJDw4G03246gaO+I2ve1ZcTxPApJAXrbJ19V4tc=; b=2r+YFQB0wwBgdp mT2BoxmbxHlbDjrOO2QuyJUYpY30XfDKiVihe8kuAcV2Dvo8dluvNxMS+k0MlslYxQg+MsCCzlgrH e7ecEO6bzQJq5/lftJlDZdZNugMAgo2scqz6WFiJHDIkhqFIUmp9hIsgGChUqyJmIoQVg9eP3oS9N FJFAPCamhYhXam53cNjQVI5jcPT03y/1s43in/PJnToRDZOK4T7Ykx0hsCO95Jp7hPHM4vMSJyyGB P0oK2otcNLiuJyN2sBsXIJirP/uPMtNyQfqCdHl1ub5rO11ejF/VABdo4H9bxIH4q0T75j4IjkxWi 4Hh0etWL4y7v1j11dwJA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nUVGr-00DQ9m-Kc; Wed, 16 Mar 2022 15:09:06 +0000 Received: from smtp-relay-internal-1.canonical.com ([185.125.188.123]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nUVGi-00DQ7J-Hh for linux-arm-kernel@lists.infradead.org; Wed, 16 Mar 2022 15:08:58 +0000 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (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-1.canonical.com (Postfix) with ESMTPS id 4C12B3F1E5 for ; Wed, 16 Mar 2022 15:08:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1647443335; bh=yPtLMahnwKOtCcXgH/ktoILLnjecC9LZzwZsY57u2dU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ftMAJmmPbXItGZhosSt7kztlKjwAy37ZYdveOU4ZWzeW9HQuFIu2Utb49ON/1b298 yWNW0nkHqT6JrbbklEI4WN1t4PZZJ6bSNlUG91LNbihiudz1sYhd+ci7qXZ+572D0R da4/3IV4l1J7YRJD1pUM2UnPPKDiHkiWmGbXGFRlVZS/VpRZfqQ5SPpc8YWnwGO5OO 9oSxLv7N5daV0WqgcG+P7hK6TU0tjUjPnk7XjWCGXQSwrkdB1OHSr9r8zn3F8AJ26b hwv4+CYATlanC9Ei9R9ANceGW02NLo+aYasl4vkEST03F+f6lnm2+2zIJoHD8rz2HJ Y+R9SffLHAtCQ== Received: by mail-wm1-f70.google.com with SMTP id q6-20020a1cf306000000b0038c5726365aso1156453wmq.3 for ; Wed, 16 Mar 2022 08:08:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yPtLMahnwKOtCcXgH/ktoILLnjecC9LZzwZsY57u2dU=; b=0tme57crGGdwSLm61/OKpWooOh6F96j1h3oPKp6rNrWJG4LwVRbj5BVYX/024ofCPY d9kvdIT9v7z3nnq0fhqpqjzUMXz6/yV4FF4Y2NMw6PBc2gx33LzkSQ2bc0GQ12JJwgic ID9yYwpAfwHlRjnDYj6HbzmvmS7u7VfVFHkvW+OFgsCgRtjSb+rJLIGM2O8EiMrwEDqB uncBxY4qaV1RcXNK+bCkNje37Fwfay+YATy25YACnv1rqf2n7TabdCqMz/2P7h0kij3v Xx1UdbeEh8LSzPJBYwQGF3PelxzV7rEdVIhF3SoiY/+VwYG28XdOy9SDj9NL/IVSjayP yO8w== X-Gm-Message-State: AOAM533t2VcXV9rZIPSwEgB9CHzybzdW/S6WDqVhSR88HCOyBRIkvnaz B5hL9Iex7GpzsHyC7YcHekNzZiaylT/CojRIMRbDrM4Vwjat87h5qVPW7UIu3z5r//gTpFIp4lB A56CbXVGy+XcBzt95T2ulQyNHjgMLgn2bjnZztRzUbXP0UhtHcfBf X-Received: by 2002:a05:600c:1e1e:b0:38b:b31f:7fc with SMTP id ay30-20020a05600c1e1e00b0038bb31f07fcmr6700405wmb.191.1647443335038; Wed, 16 Mar 2022 08:08:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyLttuQcgADlzoGu5HiDZ52KZb2YEjo0lDq9KqKlAOh9CGx+bAznJO89SsLTaClQchjThu5dg== X-Received: by 2002:a05:600c:1e1e:b0:38b:b31f:7fc with SMTP id ay30-20020a05600c1e1e00b0038bb31f07fcmr6700371wmb.191.1647443334858; Wed, 16 Mar 2022 08:08:54 -0700 (PDT) Received: from localhost.localdomain (78-11-189-27.static.ip.netia.com.pl. [78.11.189.27]) by smtp.gmail.com with ESMTPSA id u18-20020adfdd52000000b001f04e9f215fsm1895105wrm.53.2022.03.16.08.08.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 08:08:53 -0700 (PDT) From: Krzysztof Kozlowski To: Greg Kroah-Hartman , "Rafael J. Wysocki" Cc: Stuart Yoder , "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 , 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 , Andy Shevchenko , Krzysztof Kozlowski , Mark Brown Subject: [PATCH v5 07/11] spi: Use helper for safer setting of driver_override Date: Wed, 16 Mar 2022 16:07:59 +0100 Message-Id: <20220316150803.421897-1-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220316150533.421349-1-krzysztof.kozlowski@canonical.com> References: <20220316150533.421349-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220316_080856_777349_CE23CC7E X-CRM114-Status: GOOD ( 18.45 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Use a helper to set driver_override to the reduce amount of duplicated code. Signed-off-by: Krzysztof Kozlowski Reviewed-by: Mark Brown --- drivers/spi/spi.c | 26 ++++---------------------- include/linux/spi/spi.h | 2 ++ 2 files changed, 6 insertions(+), 22 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 6937cf2d59e0..34f311224c47 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -71,29 +71,11 @@ static ssize_t driver_override_store(struct device *dev, const char *buf, size_t count) { struct spi_device *spi = to_spi_device(dev); - const char *end = memchr(buf, '\n', count); - const size_t len = end ? end - buf : count; - const char *driver_override, *old; - - /* We need to keep extra room for a newline when displaying value */ - if (len >= (PAGE_SIZE - 1)) - return -EINVAL; - - driver_override = kstrndup(buf, len, GFP_KERNEL); - if (!driver_override) - return -ENOMEM; + int ret; - device_lock(dev); - old = spi->driver_override; - if (len) { - spi->driver_override = driver_override; - } else { - /* Empty string, disable driver override */ - spi->driver_override = NULL; - kfree(driver_override); - } - device_unlock(dev); - kfree(old); + ret = driver_set_override(dev, &spi->driver_override, buf, count); + if (ret) + return ret; return count; } diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h index 5f8c063ddff4..f0177f9b6e13 100644 --- a/include/linux/spi/spi.h +++ b/include/linux/spi/spi.h @@ -138,6 +138,8 @@ extern int spi_delay_exec(struct spi_delay *_delay, struct spi_transfer *xfer); * for driver coldplugging, and in uevents used for hotplugging * @driver_override: If the name of a driver is written to this attribute, then * the device will bind to the named driver and only the named driver. + * Do not set directly, because core frees it; use driver_set_override() to + * set or clear it. * @cs_gpiod: gpio descriptor of the chipselect line (optional, NULL when * not using a GPIO line) * @word_delay: delay to be inserted between consecutive From patchwork Wed Mar 16 15:08:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 12782840 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 89D3BC433EF for ; Wed, 16 Mar 2022 15:12:24 +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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=5Ye1icFdzBX1eDLSlp8ZcpJH4D/U/Qp8tljx1I5Pkhk=; b=F6SNXftdT99hUO 7Ek/UsFiuKwm7c7pRtRwpgv9Pci4ArAJ0cDy+tcQLqETb3x066fTo7vok7tvcgc5a7SjB+9GZxeft uYeoBnOulNArbpWUrzkrdyWDW2V67qcJbQzphh+UCiLokN1tE9fAuFU9mVbQCxRx3rjYixv2rRlTt Z6y4fNrghArUr0Q9AuETVP50XODEmjkSh0THEtBsoAAO//70XtbwXmp09v2TpRmimnLxVYkBZfm5k uhFY4nj5phn54G9gcww9043zbfcAQlTm1TIf+frup0MKQAEXEEXs0OCfZ3ZGktXdw9faTailPGxD/ P04d9Z6PToS6DKejiacw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nUVIO-00DR5S-TC; Wed, 16 Mar 2022 15:10:43 +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 1nUVGy-00DQEP-Sx for linux-arm-kernel@lists.infradead.org; Wed, 16 Mar 2022 15:09:14 +0000 Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.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 5F7263F1AF for ; Wed, 16 Mar 2022 15:09:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1647443348; bh=yjxT3cEgNPbxxzjxaxofFiViREMV9sxUDnIsV8OP+D8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ASPWY56z2SIG8YhPnK1HQ4g1UcPDdFDJdlDkD5cyrE9w5SX31bFizyp6RUmcz0+Zm xEQnk8u5U9EvfLguCm98Hj42FdUPRo7lVCA8kxrw96ccuuQ+LBJvGU0HzzBaZV+Mww xTtQPkMjMOqwty1GWP2xeE7ms++L23KPVXVUVnxTST94V+eHfjAOtm8770W7um7Yth D6wMWM6NYkinDoY7bog0Syk+Q0AIebvG4MCAtekPHTxzT4TgGSi0kSJCLdErRpgKDI 2eO5JIcyK0yeh1P0NP+zbauxu6pxPSHSk0jMsDx2g6yWpU8I4mIP3/Bj25OCXIWK10 6WxcgsIzw6CQw== Received: by mail-wr1-f72.google.com with SMTP id k20-20020adfc714000000b001e305cd1597so656322wrg.19 for ; Wed, 16 Mar 2022 08:09:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yjxT3cEgNPbxxzjxaxofFiViREMV9sxUDnIsV8OP+D8=; b=CUoFosa8GmsMAOj5cBUNKjfZ1Xdg5j1jHgPF6HX8rVXjdO9u9xfD+eBb7GQpcoMJzG sR9Mm68MDbwaVfzBMXUOTwnzBVUFZGmmtAhzlzBjIDrI4NKVCiVp1qqTD1pNjCbuDce9 vIW3jMSjmeuQzLT21sKBWwHfUM4I95UugfGAHacP+FJpUUHPutBwm177vtw30bsVMhGr Q2hmM+kuXIWnvFJyAG++k9wyekgs5up14M3+HEN4HcgFJ2pPVG7xTuiRmdN4tkbTU5ug 9rVDalZy9MGO0vxcg6mPwf44Xq6jqLV+ZI0asc18+Uc+s48T0YYn56spTFW9uUbD9BC0 lwcg== X-Gm-Message-State: AOAM5314TUmGXfjdcIrNtr/MFV6J8rcUtA0q6NtRuDLcpNnrV8NYL/zG kFEVZ+JMcz8sCqxoCoChvpgZ7T1T15GXDLcV2IbvKb4lv0JqY/6qS4bHa4tOaYtDeZB3sHBWGv5 DihLPZdaHRg3j4aaGUkL1eapIjitkMrGoBj5HV8F6a8+H12Sdm0FL X-Received: by 2002:a05:600c:3d8d:b0:38c:6f6e:e61a with SMTP id bi13-20020a05600c3d8d00b0038c6f6ee61amr2475305wmb.101.1647443337718; Wed, 16 Mar 2022 08:08:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwxihfOFhqnyQOV2LqVMQfkoNfvlmhYMokdGWLXgOBRd3UZepsNC84lNIG8stGIAXm3FyJnJA== X-Received: by 2002:a05:600c:3d8d:b0:38c:6f6e:e61a with SMTP id bi13-20020a05600c3d8d00b0038c6f6ee61amr2475269wmb.101.1647443337539; Wed, 16 Mar 2022 08:08:57 -0700 (PDT) Received: from localhost.localdomain (78-11-189-27.static.ip.netia.com.pl. [78.11.189.27]) by smtp.gmail.com with ESMTPSA id u18-20020adfdd52000000b001f04e9f215fsm1895105wrm.53.2022.03.16.08.08.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 08:08:56 -0700 (PDT) From: Krzysztof Kozlowski To: Greg Kroah-Hartman , "Rafael J. Wysocki" Cc: Stuart Yoder , "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 , 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 , Andy Shevchenko , Krzysztof Kozlowski , "Michael S . Tsirkin" Subject: [PATCH v5 08/11] vdpa: Use helper for safer setting of driver_override Date: Wed, 16 Mar 2022 16:08:00 +0100 Message-Id: <20220316150803.421897-2-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220316150533.421349-1-krzysztof.kozlowski@canonical.com> References: <20220316150533.421349-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220316_080913_121160_6E201C36 X-CRM114-Status: GOOD ( 17.18 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Use a helper to set driver_override to the reduce amount of duplicated code. Signed-off-by: Krzysztof Kozlowski Acked-by: Michael S. Tsirkin --- drivers/vdpa/vdpa.c | 29 ++++------------------------- include/linux/vdpa.h | 4 +++- 2 files changed, 7 insertions(+), 26 deletions(-) diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c index 1ea525433a5c..2dabed1df35c 100644 --- a/drivers/vdpa/vdpa.c +++ b/drivers/vdpa/vdpa.c @@ -77,32 +77,11 @@ static ssize_t driver_override_store(struct device *dev, const char *buf, size_t count) { struct vdpa_device *vdev = dev_to_vdpa(dev); - const char *driver_override, *old; - char *cp; + int ret; - /* We need to keep extra room for a newline */ - if (count >= (PAGE_SIZE - 1)) - return -EINVAL; - - driver_override = kstrndup(buf, count, GFP_KERNEL); - if (!driver_override) - return -ENOMEM; - - cp = strchr(driver_override, '\n'); - if (cp) - *cp = '\0'; - - device_lock(dev); - old = vdev->driver_override; - if (strlen(driver_override)) { - vdev->driver_override = driver_override; - } else { - kfree(driver_override); - vdev->driver_override = NULL; - } - device_unlock(dev); - - kfree(old); + ret = driver_set_override(dev, &vdev->driver_override, buf, count); + if (ret) + return ret; return count; } diff --git a/include/linux/vdpa.h b/include/linux/vdpa.h index 721089bb4c84..37117404660e 100644 --- a/include/linux/vdpa.h +++ b/include/linux/vdpa.h @@ -64,7 +64,9 @@ struct vdpa_mgmt_dev; * struct vdpa_device - representation of a vDPA device * @dev: underlying device * @dma_dev: the actual device that is performing DMA - * @driver_override: driver name to force a match + * @driver_override: driver name to force a match; do not set directly, + * because core frees it; use driver_set_override() to + * set or clear it. * @config: the configuration ops for this device. * @cf_mutex: Protects get and set access to configuration layout. * @index: device index From patchwork Wed Mar 16 15:08:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 12782841 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 D4C9DC433F5 for ; Wed, 16 Mar 2022 15:12:52 +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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=3xeOjl4Pbw5+Se48Pun57/Ln3Suqe4zg5Hejo2GY2qc=; b=jx1NF5BynLvGNu OET57hwr0ne473+p+XHVAzsY9AuJyURE9ac/6QBIU3L0ikCN2wT5lpleSQCBiQaGfrlYNGRUqlzf4 y+avEIt/mvcG7o9a/DvJOD/DSkjRILKt5BYUnCbHvkKgiXKe846vSgHSWYZx7U+jei+aaNlTio4HI vDfXFfShzs0ZPOI+qYd/gns3eGcTBlBak/T8n18TZk8dhft/0c+hNfA1Coq5EVCY+NGCfP4ucLH8O kfiw4hIT64a+8aedcPJmiYqLf5f+z8xnaWoQLKTgBki8B44IjuaPfs0zEX+TUqITHGRfLgN1OwifT b3RDlxs0mhWTZnErJHvA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nUVJ6-00DRQh-Dm; Wed, 16 Mar 2022 15:11:25 +0000 Received: from smtp-relay-internal-1.canonical.com ([185.125.188.123]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nUVGz-00DQGN-BU for linux-arm-kernel@lists.infradead.org; Wed, 16 Mar 2022 15:09:14 +0000 Received: from mail-lj1-f197.google.com (mail-lj1-f197.google.com [209.85.208.197]) (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-1.canonical.com (Postfix) with ESMTPS id 122D43F798 for ; Wed, 16 Mar 2022 15:09:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1647443352; bh=0TkaUHsdiaalOGmdOdYbrrLuoBcQ76N1kyxAw52pHyQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=jyHht3XCLNr8VV2B/uTpzBkSInAMbmI/OgaxwuNmMa3xzDLPvAgITmvgRbvbAXnCa CaP/7VEhfYJWX+DtRZdBZ64KUBKWE1vAwJSWpqXxFXw6lFdFjmd3CCKEZ3UUQ7mAqG LphkR5ZMxUp3ep/FzIqHqol6T1yalNIFlqJzB0xMos5H70hWwhe5VgAYXG8ATxB5w2 o/vzY7Z3+bIQwQGI5Yer4V1vNAurqUcNpUCQqXpFYgbJpK1GhBM75dch+CId9Pr79a yopE++kbJngLbpOU/WNUH+pXUOwW8f1PAGwzsWGLd2vIw9d8IeX1cs9hWy/1Yza19r zu3mbXUZ8FsHQ== Received: by mail-lj1-f197.google.com with SMTP id x3-20020a05651c104300b00247ebe980b7so1025340ljm.11 for ; Wed, 16 Mar 2022 08:09:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0TkaUHsdiaalOGmdOdYbrrLuoBcQ76N1kyxAw52pHyQ=; b=0i+pkGDqMRs2f1ywc/xUVe1QVPxVW8DUsz8ZvenxDN7HpsL6tmOlMXB6sqE6iZhbLB QfEF2mNGrBSUyumKGzK1bzchgxNLFG56D1rkrQWCA65xubuD76N4SKW9whg1CV/1N0ZW vLZcErMZlcPatnAeraAIyM5PeQ6pgZHpyGTXc7hkdO73tMQROBPvkw3pg3ewwBq14Rsh WrrTBm+uuWN92aXCOgc560xtpWIt1y9b2Dg7Xkd5H5m8Yh650B4ibk9oSJ9kkKD3N28/ V/2YVOExuq/ljB9TxX9ynxJEQpsoicsnPEYv4bO5iz9PIzY6CIAhbnRf2tOhPlItDJwR RzGQ== X-Gm-Message-State: AOAM532fQnVwAdq2Eg56blvaKguZQiU4N+MM29fGpRl7QLn2Xa6OF3AO i8d9XYmoq+KrlYd1UjOCWSOvJowlQwCY85fNShWPEfRT7VpCMyLJ28SNSqjyGrHdzbw4jL4arpV 7o+qRuL+AgDoBuM7qIbNuXwYVLIOrjmdrT41oFMy2DMnYDaIFsVwZ X-Received: by 2002:a5d:6442:0:b0:203:dff2:866c with SMTP id d2-20020a5d6442000000b00203dff2866cmr272607wrw.465.1647443340523; Wed, 16 Mar 2022 08:09:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwnOg2aSuuzk/AN13SVnFGjUvC/KtTXL980cTeRfOeIj0D4M/X0M0ZN717fC4+xLvcCtZ4GNg== X-Received: by 2002:a5d:6442:0:b0:203:dff2:866c with SMTP id d2-20020a5d6442000000b00203dff2866cmr272574wrw.465.1647443340291; Wed, 16 Mar 2022 08:09:00 -0700 (PDT) Received: from localhost.localdomain (78-11-189-27.static.ip.netia.com.pl. [78.11.189.27]) by smtp.gmail.com with ESMTPSA id u18-20020adfdd52000000b001f04e9f215fsm1895105wrm.53.2022.03.16.08.08.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 08:08:59 -0700 (PDT) From: Krzysztof Kozlowski To: Greg Kroah-Hartman , "Rafael J. Wysocki" Cc: Stuart Yoder , "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 , 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 , Andy Shevchenko , Krzysztof Kozlowski , stable@vger.kernel.org, Stephen Boyd Subject: [PATCH v5 09/11] clk: imx: scu: Fix kfree() of static memory on setting driver_override Date: Wed, 16 Mar 2022 16:08:01 +0100 Message-Id: <20220316150803.421897-3-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220316150533.421349-1-krzysztof.kozlowski@canonical.com> References: <20220316150533.421349-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220316_080913_582123_6DF9AB8C X-CRM114-Status: GOOD ( 13.94 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The driver_override field from platform driver should not be initialized from static memory (string literal) because the core later kfree() it, for example when driver_override is set via sysfs. Use dedicated helper to set driver_override properly. Fixes: 77d8f3068c63 ("clk: imx: scu: add two cells binding support") Cc: Signed-off-by: Krzysztof Kozlowski Acked-by: Stephen Boyd --- drivers/clk/imx/clk-scu.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/clk/imx/clk-scu.c b/drivers/clk/imx/clk-scu.c index 083da31dc3ea..4b2268b7d0d0 100644 --- a/drivers/clk/imx/clk-scu.c +++ b/drivers/clk/imx/clk-scu.c @@ -683,7 +683,12 @@ struct clk_hw *imx_clk_scu_alloc_dev(const char *name, return ERR_PTR(ret); } - pdev->driver_override = "imx-scu-clk"; + ret = driver_set_override(&pdev->dev, &pdev->driver_override, + "imx-scu-clk", strlen("imx-scu-clk")); + if (ret) { + platform_device_put(pdev); + return ERR_PTR(ret); + } ret = imx_clk_scu_attach_pd(&pdev->dev, rsrc_id); if (ret) From patchwork Wed Mar 16 15:08:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 12782839 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 24DE6C433EF for ; Wed, 16 Mar 2022 15:11:36 +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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=GmeQJPKeBxwj/QO04WZsH7dTv19gl7ycsNCHqYVz8a0=; b=vWzU+QEKqv+np+ YR3ohgZljpyCd0+Fqgdd1v1fz9q1Yk7b/Re22+dd9VxjKteBFcheKOPpaisXu8vg7k7H1fFLFz08h +Ea0c8MnldfQvJ2z9uoNEtQI7aN0YgkSbBnxph9eOO0sa6HXZLGCRUbvFxsfDi0g9P9GvVUkmrak1 yvQ9BoOjWX/vHMpq8SB51tyi7zMnJK/HG+1X1e/Pbi3dyKEnPB33R8F+cVjfBQv3JMXqajC+Upv7/ QZ63x6hmUsavO4cMcEpM7kQ9Y462JkmmfAFcar9Pux+mhQo/99xvxSWasQU/BeWoO+9yXpZf5zyiN uSHOMwEPKStzl0jQtDAw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nUVHh-00DQeg-0I; Wed, 16 Mar 2022 15:09:57 +0000 Received: from smtp-relay-internal-1.canonical.com ([185.125.188.123]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nUVGs-00DQC9-6u for linux-arm-kernel@lists.infradead.org; Wed, 16 Mar 2022 15:09:07 +0000 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (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-1.canonical.com (Postfix) with ESMTPS id 6A1FF3FA7E for ; Wed, 16 Mar 2022 15:09:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1647443344; bh=T7JLnH9mqiYxWSJ2Xi+hqpmFTONALX95DZP9Prs/CTQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=i2Xb9MhzTdE+lE9OaTOdm5lssR7LIHkhHZcQk+GxGLVjMfzP4q1EpOl3OmDLCn2Hs xU9kPLuL9sHGb7idnp2OtNcmSuB4xVMRzL3HzTHZdNW1ymEgq4viYGLlH0hz/iM2kF OUHlYcrpm53zPfWgiyUoaW6Zazou2yZE2B49ntkQLPLldE016K5wwGugtm6h2iFTWP IuRj79EG5Tb2kM6rxrh0JB9pk8XmeNKc7VUJQpofWCNT6Q3E+wN7lypAPutcjtoM2C vPsjUybK5SbgBJvpheJtVoNPys+5w99huk6JJGlK7Q5kLoDEsM/xD372DKnYJDkptG cyKm6ONJJSLhw== Received: by mail-wm1-f70.google.com with SMTP id c126-20020a1c3584000000b00380dee8a62cso807294wma.8 for ; Wed, 16 Mar 2022 08:09:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=T7JLnH9mqiYxWSJ2Xi+hqpmFTONALX95DZP9Prs/CTQ=; b=tpznC9qnR6p3WapA82iQ2UEvPi61WyaBsb8GyPqSxU4wBaUGt6ALFQmuzoSgTr0sYx KwOsyDo5L+L/aL2W3v6kRGAJw+5dmoLG1y32bS9l+fjt7ZWnDr42CE1THemAUVYnkVSa /ss2SQta6nEasLMxL8j9I0ZQlDUYTW5CCvgo/4ZJUo49QTLVvEBJX1nj7fsARLYoraet zio/av0JENMSsxlRtx5CEhIMC0t5Vemzv8fKqv6KSP3yANHYEQBjxH72ZqmtnlkgPt1G hkpjF4eA3LYQXP33jlcBikhYXvs/lp21VOaCrzJ7Jb3+WBuo4JMphP5VRvwP1bW/6+Ht AhTQ== X-Gm-Message-State: AOAM530+NRFkg8MzWqZSp0s+Og9Rl/YJBC0OKIaGfiSdfCwP7eEmLYMy EGyKZLjJ0J61JRGCfOgMx7mes7o975OytT9yANQtMLybOr/sHIt1anmJmXlbePnxCWbCJpOVAzq Rz3q44xJafMHewVyxJJXwaUUp4AjohWyLIGWyIXxz9IKeGa+TRi7R X-Received: by 2002:adf:816b:0:b0:203:7fae:a245 with SMTP id 98-20020adf816b000000b002037faea245mr273597wrm.619.1647443343705; Wed, 16 Mar 2022 08:09:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyiZS5X9++Ir6ARAdY07waJfT3FXmo4jW7vzpJuptfIiZFzTOsJAweK7fuoToT0HCAq1Xxe+Q== X-Received: by 2002:adf:816b:0:b0:203:7fae:a245 with SMTP id 98-20020adf816b000000b002037faea245mr273589wrm.619.1647443343503; Wed, 16 Mar 2022 08:09:03 -0700 (PDT) Received: from localhost.localdomain (78-11-189-27.static.ip.netia.com.pl. [78.11.189.27]) by smtp.gmail.com with ESMTPSA id u18-20020adfdd52000000b001f04e9f215fsm1895105wrm.53.2022.03.16.08.09.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 08:09:01 -0700 (PDT) From: Krzysztof Kozlowski To: Greg Kroah-Hartman , "Rafael J. Wysocki" Cc: Stuart Yoder , "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 , 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 , Andy Shevchenko , Krzysztof Kozlowski , stable@vger.kernel.org, Srinivas Kandagatla Subject: [PATCH v5 10/11] slimbus: qcom-ngd: Fix kfree() of static memory on setting driver_override Date: Wed, 16 Mar 2022 16:08:02 +0100 Message-Id: <20220316150803.421897-4-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220316150533.421349-1-krzysztof.kozlowski@canonical.com> References: <20220316150533.421349-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220316_080906_419082_7E1A8791 X-CRM114-Status: GOOD ( 15.11 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The driver_override field from platform driver should not be initialized from static memory (string literal) because the core later kfree() it, for example when driver_override is set via sysfs. Use dedicated helper to set driver_override properly. Fixes: 917809e2280b ("slimbus: ngd: Add qcom SLIMBus NGD driver") Cc: Signed-off-by: Krzysztof Kozlowski Reviewed-by: Srinivas Kandagatla --- drivers/slimbus/qcom-ngd-ctrl.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/slimbus/qcom-ngd-ctrl.c b/drivers/slimbus/qcom-ngd-ctrl.c index 0f29a08b4c09..0aa8408464ad 100644 --- a/drivers/slimbus/qcom-ngd-ctrl.c +++ b/drivers/slimbus/qcom-ngd-ctrl.c @@ -1434,6 +1434,7 @@ static int of_qcom_slim_ngd_register(struct device *parent, const struct of_device_id *match; struct device_node *node; u32 id; + int ret; match = of_match_node(qcom_slim_ngd_dt_match, parent->of_node); data = match->data; @@ -1455,7 +1456,17 @@ static int of_qcom_slim_ngd_register(struct device *parent, } ngd->id = id; ngd->pdev->dev.parent = parent; - ngd->pdev->driver_override = QCOM_SLIM_NGD_DRV_NAME; + + ret = driver_set_override(&ngd->pdev->dev, + &ngd->pdev->driver_override, + QCOM_SLIM_NGD_DRV_NAME, + strlen(QCOM_SLIM_NGD_DRV_NAME)); + if (ret) { + platform_device_put(ngd->pdev); + kfree(ngd); + of_node_put(node); + return ret; + } ngd->pdev->dev.of_node = node; ctrl->ngd = ngd; From patchwork Wed Mar 16 15:08:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 12782842 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 D8968C433F5 for ; Wed, 16 Mar 2022 15:13:33 +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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=fYFduTH2rM9lR7AvDF9wPoUqAjxdYQM/b2A+H/3etbg=; b=SRlAEzv1Xf4vtP 9F20jIIaN4f7KbbCv1oWMuBogOawQXYPsfvESirhnp+Dwvs4YX+CNd0jHBEqJjiR1IgRwdkm5cGEs I3Z1x0xPBqLDWLKMKXDqmE4AIcTiI7LVOvfDM7+JBensptYT4z0W/sEnAl603DDHBfDf3iijIyapP kN1KZNf4LPyqo8VIjJOzhN1shJepKBaeIUGXSFokSgd/uvFlthyG7hOWziYeJ7xPFIXeqfQBpyry2 uOv4R+rO5pzbnRYrEAMpF+9EqckWzmUoH+uNbZ+kd9YoXSAp/F5sbgj3liI2UuqCAv91i2z+ILrRn tFBggCfuAGBrvz7qyBwA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nUVJc-00DRbV-MG; Wed, 16 Mar 2022 15:11:57 +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 1nUVH8-00DQLQ-Kf for linux-arm-kernel@lists.infradead.org; Wed, 16 Mar 2022 15:09:25 +0000 Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (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 3A53D3F619 for ; Wed, 16 Mar 2022 15:09:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1647443361; bh=pKuO1Pnb8DTWNu323Li1Km8nI1auNgT3IB1hncz5HlI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=BSTNHPtMl19x5uWONs9Y6eE7TQXKVW4jTUT+YyuR3SkQyIv/v7Tffbfq2wcDN4eSu qIaPaTYI4N9X9wEy8819i8MFChecIGxh7D5LMdYHHiyxrQ0Zrylnb6oGrtWkCRxGzC c21S8arsu0i5GKIB5H7HxOmdjH3TQi1dTN069oHtVrijUeddMkFrevZXWDbIY0ZLCD +qrfUB5Lo+RaYapkzWZh3tyfk3NcwsFHn7izSeOGC2479f8KYGu12Ylh2ueutLAps9 +iJ5JTA6droBecaTn3TgG4WtLLhmLXE5e+cNhPNYxlHdK1xin4k+NTPEM151nla6M/ WLGE4wm1tJ4bg== Received: by mail-wr1-f71.google.com with SMTP id q4-20020adfc504000000b00203e15159e8so543422wrf.6 for ; Wed, 16 Mar 2022 08:09:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pKuO1Pnb8DTWNu323Li1Km8nI1auNgT3IB1hncz5HlI=; b=hJCTlKwMSJNyaAjJDfWiBZBPtXZCtkJvRg3ptU5ONztj4hB26EdBa/nuInGXJaCu0L FTsfaIF0nRh+awYbTKtKJ0lfIM6tloltimtZTZZimqK6+XT0rreOmoijO2DeKy/VDFsd b9rPbdPEQRw02sDps8d8RB/Jjd/XGG3z+ZSSsLQo+k5O9i+hCcSLfiFXUhKMZ0/MCn2t hTL276J5uN0NgJQ9nL1Kv7+glIsrYjLxejwB1jQb8k4Ktnk99KnpPyJQHCzYLyBbrhTa TzBM4OKyDbFmHJNtL9XoBaAH7WzD2lOttkebL/qhd/vy37y5ikn6KIyTu/7XKDzS0sFX 59ug== X-Gm-Message-State: AOAM532QfJrWkYPw8bvv11D9mD+t09JXeVZ2z8LyhEQA6Q4s+2ykmw84 xmp5e0IyajGSIvYESjBOgZ5Dqc5kNP25Fg5sO9AGUM1NYViHfrxZrQ0kjlglFOUFfQllIWVmOFx 0D2e6f0c3ZJC5pJv8c7HOpP0fNsZGwkhUp9GQDH8bAaihLPhYvn3o X-Received: by 2002:a05:600c:3508:b0:38b:cc1f:a99b with SMTP id h8-20020a05600c350800b0038bcc1fa99bmr6311341wmq.197.1647443348140; Wed, 16 Mar 2022 08:09:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwvsOYZ+nBmu9loCTPKjgh/9mwESfnIbe8Inxn1yryPkv1+wBIJxw3Cp/IL2PJnd3eHgVih9w== X-Received: by 2002:a05:600c:3508:b0:38b:cc1f:a99b with SMTP id h8-20020a05600c350800b0038bcc1fa99bmr6311319wmq.197.1647443347937; Wed, 16 Mar 2022 08:09:07 -0700 (PDT) Received: from localhost.localdomain (78-11-189-27.static.ip.netia.com.pl. [78.11.189.27]) by smtp.gmail.com with ESMTPSA id u18-20020adfdd52000000b001f04e9f215fsm1895105wrm.53.2022.03.16.08.09.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 08:09:05 -0700 (PDT) From: Krzysztof Kozlowski To: Greg Kroah-Hartman , "Rafael J. Wysocki" Cc: Stuart Yoder , "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 , 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 , Andy Shevchenko , Krzysztof Kozlowski , stable@vger.kernel.org Subject: [PATCH v5 11/11] rpmsg: Fix kfree() of static memory on setting driver_override Date: Wed, 16 Mar 2022 16:08:03 +0100 Message-Id: <20220316150803.421897-5-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220316150533.421349-1-krzysztof.kozlowski@canonical.com> References: <20220316150533.421349-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220316_080922_873726_564E88D7 X-CRM114-Status: GOOD ( 17.25 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The driver_override field from platform driver should not be initialized from static memory (string literal) because the core later kfree() it, for example when driver_override is set via sysfs. Use dedicated helper to set driver_override properly. Fixes: 950a7388f02b ("rpmsg: Turn name service into a stand alone driver") Fixes: c0cdc19f84a4 ("rpmsg: Driver for user space endpoint interface") Cc: Signed-off-by: Krzysztof Kozlowski Reviewed-by: Bjorn Andersson --- drivers/rpmsg/rpmsg_core.c | 3 ++- drivers/rpmsg/rpmsg_internal.h | 11 +++++++++-- drivers/rpmsg/rpmsg_ns.c | 14 ++++++++++++-- include/linux/rpmsg.h | 6 ++++-- 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/drivers/rpmsg/rpmsg_core.c b/drivers/rpmsg/rpmsg_core.c index 79368a957d89..95fc283f6af7 100644 --- a/drivers/rpmsg/rpmsg_core.c +++ b/drivers/rpmsg/rpmsg_core.c @@ -400,7 +400,8 @@ field##_store(struct device *dev, struct device_attribute *attr, \ const char *buf, size_t sz) \ { \ struct rpmsg_device *rpdev = to_rpmsg_device(dev); \ - char *new, *old; \ + const char *old; \ + char *new; \ \ new = kstrndup(buf, sz, GFP_KERNEL); \ if (!new) \ diff --git a/drivers/rpmsg/rpmsg_internal.h b/drivers/rpmsg/rpmsg_internal.h index d4b23fd019a8..dd1f4ed616b6 100644 --- a/drivers/rpmsg/rpmsg_internal.h +++ b/drivers/rpmsg/rpmsg_internal.h @@ -95,9 +95,16 @@ int rpmsg_release_channel(struct rpmsg_device *rpdev, static inline int rpmsg_ctrldev_register_device(struct rpmsg_device *rpdev) { strcpy(rpdev->id.name, "rpmsg_ctrl"); - rpdev->driver_override = "rpmsg_ctrl"; + ret = driver_set_override(&rpdev->dev, &rpdev->driver_override, + "rpmsg_ctrl", strlen("rpmsg_ctrl")); + if (ret) + return ret; - return rpmsg_register_device(rpdev); + ret = rpmsg_register_device(rpdev); + if (ret) + kfree(rpdev->driver_override); + + return ret; } #endif diff --git a/drivers/rpmsg/rpmsg_ns.c b/drivers/rpmsg/rpmsg_ns.c index 762ff1ae279f..95a51543f5ad 100644 --- a/drivers/rpmsg/rpmsg_ns.c +++ b/drivers/rpmsg/rpmsg_ns.c @@ -20,12 +20,22 @@ */ int rpmsg_ns_register_device(struct rpmsg_device *rpdev) { + int ret; + strcpy(rpdev->id.name, "rpmsg_ns"); - rpdev->driver_override = "rpmsg_ns"; + ret = driver_set_override(&rpdev->dev, &rpdev->driver_override, + "rpmsg_ns", strlen("rpmsg_ns")); + if (ret) + return ret; + rpdev->src = RPMSG_NS_ADDR; rpdev->dst = RPMSG_NS_ADDR; - return rpmsg_register_device(rpdev); + ret = rpmsg_register_device(rpdev); + if (ret) + kfree(rpdev->driver_override); + + return ret; } EXPORT_SYMBOL(rpmsg_ns_register_device); diff --git a/include/linux/rpmsg.h b/include/linux/rpmsg.h index 02fa9116cd60..20c8cd1cde21 100644 --- a/include/linux/rpmsg.h +++ b/include/linux/rpmsg.h @@ -41,7 +41,9 @@ struct rpmsg_channel_info { * rpmsg_device - device that belong to the rpmsg bus * @dev: the device struct * @id: device id (used to match between rpmsg drivers and devices) - * @driver_override: driver name to force a match + * @driver_override: driver name to force a match; do not set directly, + * because core frees it; use driver_set_override() to + * set or clear it. * @src: local address * @dst: destination address * @ept: the rpmsg endpoint of this channel @@ -51,7 +53,7 @@ struct rpmsg_channel_info { struct rpmsg_device { struct device dev; struct rpmsg_device_id id; - char *driver_override; + const char *driver_override; u32 src; u32 dst; struct rpmsg_endpoint *ept;