From patchwork Sun Feb 27 13:52:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 12761739 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BE9CDC4332F for ; Sun, 27 Feb 2022 13:52:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231309AbiB0Nxc (ORCPT ); Sun, 27 Feb 2022 08:53:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231260AbiB0Nx0 (ORCPT ); Sun, 27 Feb 2022 08:53:26 -0500 Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05BD0E0A4 for ; Sun, 27 Feb 2022 05:52:49 -0800 (PST) Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.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-1.canonical.com (Postfix) with ESMTPS id B39823F1DD for ; Sun, 27 Feb 2022 13:52:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645969963; bh=CdJmQ2T6u9FeKBCl3rxyT2dhiXMmAcmjIg9rruFo2ow=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=gaZpAzZTdYWiFNsWMstsc7J3qYKtczSXiIHesilMo8wiUGC0nCR/D2ZQM3CVclIOe XILMCy4dYGojvu91yc3kCjKjrZrOR/IwkAZwluguhUciBiopsAeg1PcWMjB4qmSwHI VON3IMWXyIqA/lrwLHjAp66U/N4nCdWNoy9VKl/x/cht3fVk/eYL9rVSo/sp0GE/ib m218SzPIChYQ6iGBSkm0K6qhz9gD8E30cvlQw2T7vEFBWKlXKZnyTZsjHwh7nJmV3t z5PDKotkDx20d3egkyDj+Ncjcwnw3sJYiLJprzClSBh3dZwQDZY2nu5zBT9V0ptCnv 3ZZL8vkJXEEbQ== Received: by mail-ed1-f71.google.com with SMTP id b13-20020a056402278d00b0041311e02a9bso4196734ede.13 for ; Sun, 27 Feb 2022 05:52:43 -0800 (PST) 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=CdJmQ2T6u9FeKBCl3rxyT2dhiXMmAcmjIg9rruFo2ow=; b=X6qwvogePBZX9S9wUhbS4xCcIMsMM2aMCnA0D7Q87jcs4sUNvyc+0uonLD4kl0K1Kq XgcteISuPH2oXcGeexNIhw4h9BDbmd7dWNrR80Fk5GBcrD25/hd3AR2Fgfgzh/40N9zg JoIJCnN1POPzKnXBH01D2bvrCGhIkYrkEsSyt9if5AVuxt9Yi+mBMJPY19p0Z4C0H/Vn Uj9r4+sDj6DdFm0Kc+8BAjqus1pQT6PD3+XqNyX7kXcJg4OCqlBwEtdtzwMY7k49NETc IqSX4QB7XMRuCbwS5+nZYWoiyAemtBt73EdCP8olMdwvBYQHkO3jKBcyt1IAVSjbRbKm /RDA== X-Gm-Message-State: AOAM5338OckCDh5FOQic69XExPvuY+IwR5+qsxdXFB4hlB7X21qh2NnC 0YcmxCGqyp7YyiUgZuokNAVlRlSdkb3DjfmTpIQaap/5PAROoE8fqB73+iv0yQ+0XnrszOuGTgD Ek2d8ee6kVrl9h6jblw6xod8iNyD2kb0zisHNMSskqoz5EMI= X-Received: by 2002:a05:6402:369a:b0:413:81b5:7b64 with SMTP id ej26-20020a056402369a00b0041381b57b64mr9401233edb.163.1645969952737; Sun, 27 Feb 2022 05:52:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJyF4Q2ceWWkBw+ukKwS0w45tHqUR1K1BR9aZlTk16YhD7kVeeZkMAYbPmW3o4XMDt8dIFgVAQ== X-Received: by 2002:a05:6402:369a:b0:413:81b5:7b64 with SMTP id ej26-20020a056402369a00b0041381b57b64mr9401196edb.163.1645969952506; Sun, 27 Feb 2022 05:52:32 -0800 (PST) Received: from localhost.localdomain (xdsl-188-155-181-108.adslplus.ch. [188.155.181.108]) by smtp.gmail.com with ESMTPSA id r22-20020a17090638d600b006d584aaa9c9sm3393333ejd.133.2022.02.27.05.52.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Feb 2022 05:52:31 -0800 (PST) From: Krzysztof Kozlowski To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Stuart Yoder , Laurentiu Tudor , Abel Vesa , Shawn Guo , Sascha Hauer , Fabio Estevam , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , Wei Liu , Dexuan Cui , Bjorn Helgaas , Bjorn Andersson , Mathieu Poirier , Vineeth Vijayan , Peter Oberparleiter , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Andy Gross , Srinivas Kandagatla , Mark Brown , "Michael S. Tsirkin" , Jason Wang , linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, NXP Linux Team , linux-arm-kernel@lists.infradead.org, linux-hyperv@vger.kernel.org, linux-pci@vger.kernel.org, linux-remoteproc@vger.kernel.org, linux-s390@vger.kernel.org, linux-arm-msm@vger.kernel.org, alsa-devel@alsa-project.org, linux-spi@vger.kernel.org, virtualization@lists.linux-foundation.org, Linus Torvalds Cc: Rasmus Villemoes , Krzysztof Kozlowski Subject: [PATCH v3 01/11] driver: platform: Add helper for safer setting of driver_override Date: Sun, 27 Feb 2022 14:52:04 +0100 Message-Id: <20220227135214.145599-2-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220227135214.145599-1-krzysztof.kozlowski@canonical.com> References: <20220227135214.145599-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.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) (do_one_initcall) from [] (kernel_init_freeable+0x3d0/0x4d8) (kernel_init_freeable) from [] (kernel_init+0x8/0x114) (kernel_init) from [] (ret_from_fork+0x14/0x20) Provide a helper which clearly documents the usage of driver_override. This will allow later to reuse the helper and reduce amount of duplicated code. Convert the platform driver to use new helper and make the driver_override field const char (it is not modified by the core). Signed-off-by: Krzysztof Kozlowski --- drivers/base/driver.c | 51 +++++++++++++++++++++++++++++++++ drivers/base/platform.c | 28 +++--------------- include/linux/device/driver.h | 2 ++ include/linux/platform_device.h | 7 ++++- 4 files changed, 63 insertions(+), 25 deletions(-) diff --git a/drivers/base/driver.c b/drivers/base/driver.c index 8c0d33e182fd..353750b0bbc5 100644 --- a/drivers/base/driver.c +++ b/drivers/base/driver.c @@ -30,6 +30,57 @@ static struct device *next_device(struct klist_iter *i) return dev; } +/** + * driver_set_override() - Helper to set or clear driver override. + * @dev: Device to change + * @override: Address of string to change (e.g. &device->driver_override); + * The contents will be freed and hold newly allocated override. + * @s: NUL terminated string, new driver name to force a match, pass empty + * string to clear it + * @len: length of @s + * + * Helper to set or clear driver override in a device, intended for the cases + * when the driver_override field is allocated by driver/bus code. + * + * Returns: 0 on success or a negative error code on failure. + */ +int driver_set_override(struct device *dev, const char **override, + const char *s, size_t len) +{ + const char *new, *old; + char *cp; + + if (!dev || !override || !s) + return -EINVAL; + + /* We need to keep extra room for a newline */ + if (len >= (PAGE_SIZE - 1)) + return -EINVAL; + + new = kstrndup(s, len, GFP_KERNEL); + if (!new) + return -ENOMEM; + + cp = strchr(new, '\n'); + if (cp) + *cp = '\0'; + + device_lock(dev); + old = *override; + if (cp != new) { + *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 6cb04ac48bf0..8dd87f44bd74 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..e39963889aa3 100644 --- a/include/linux/platform_device.h +++ b/include/linux/platform_device.h @@ -31,7 +31,12 @@ 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 Sun Feb 27 13:52:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 12761736 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5DC35C433EF for ; Sun, 27 Feb 2022 13:52:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230177AbiB0NxW (ORCPT ); Sun, 27 Feb 2022 08:53:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231238AbiB0NxV (ORCPT ); Sun, 27 Feb 2022 08:53:21 -0500 Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40D1F65A4 for ; Sun, 27 Feb 2022 05:52:42 -0800 (PST) Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.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-1.canonical.com (Postfix) with ESMTPS id C603C402F6 for ; Sun, 27 Feb 2022 13:52:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645969954; bh=m4/zffFNkZQ1c8QkZX27EHIqdt+D+lrYYYcC+6RBnKM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=oxTHKuizKnfVrMj+ob15reDKgFyQGVThIe6lFkgledhCWWerBcS4wlg2oLYhIG1Le zh2NWcWeQPeEHdTe3A6dJW8Z4i/KAFzVHokYwn8TEfP3u0mPo3Ut9Wsys9GfpyJQrr btrqe0tHJcsACxOZ7tke6amglpbi1721YVRq1AIyCODdEXONE0pwMt9b3BU4sTZSQ7 8fZnwQJl2Xg7hEIAk/XcYJqu2Gis3Ry9YbH57FHnW1M7XrV0rS0FGc1zzyVBJzEJdn NszgSCTalQiNKV0ga0bq2lbV7AKgT8HCaxk3s0TPEGYEPHcxcPzjOltcld2zk8pLHq aXKqvrZIgh/9g== Received: by mail-ed1-f72.google.com with SMTP id cm27-20020a0564020c9b00b004137effc24bso2415888edb.10 for ; Sun, 27 Feb 2022 05:52:34 -0800 (PST) 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=m4/zffFNkZQ1c8QkZX27EHIqdt+D+lrYYYcC+6RBnKM=; b=u1NWysSOhkX3W+j++W4hlaFttBmLqGggNzwO6ijuD+AeCddZzEoj5/r1fKg6GMKhEE Ey1YPkzKjWSmQ9AcpFYGzAMMPvFqo/1tHNI3eZDlSvsSZEDKoJfikqjkV5pjybJXIcjq JjZuCOR0mNBqId7xFGLsGJyA2a4eD/teobIA5SHUxY7puIBERdCcuZlcpUyoJw1ImzEx 8HxRjDzvqsaxLPw5xEnERgx9wJYrq718h5yvh/wDTcAspIRBiO/N97clgTT7Fk64OxcY QUk65/CgmjVoP5NGZTfDf2muc/fC5W4wi6UiiN0DEr9oeUWm3p5I3lPW/w0DHlURAtOc uBxQ== X-Gm-Message-State: AOAM530tWzrpXQicfy1YoFG4/VcOiB0wqy5cd8o7+3u1Xv7P/DCTCeqL KXhc71SyB73vzXNucWCGQLRhZQVRAuL4P4MPObiNbH/0dVHdxjxgrrdHaTgBiwa/VDHymJeE/9h JvIN64DYkJOWy/zXly7c+/RabFtpBbDfhkFqSs9g1pSpyXRE= X-Received: by 2002:a17:906:4a09:b0:6d0:7f19:d738 with SMTP id w9-20020a1709064a0900b006d07f19d738mr12036153eju.76.1645969954375; Sun, 27 Feb 2022 05:52:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJyDrA1IPUhAcFT/Pi1MZ832Wj6CLhe3h27Schy7iuQVqfDwWSjNQI4J+6UflVGRe+cHgFDDSw== X-Received: by 2002:a17:906:4a09:b0:6d0:7f19:d738 with SMTP id w9-20020a1709064a0900b006d07f19d738mr12036129eju.76.1645969954167; Sun, 27 Feb 2022 05:52:34 -0800 (PST) Received: from localhost.localdomain (xdsl-188-155-181-108.adslplus.ch. [188.155.181.108]) by smtp.gmail.com with ESMTPSA id r22-20020a17090638d600b006d584aaa9c9sm3393333ejd.133.2022.02.27.05.52.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Feb 2022 05:52:33 -0800 (PST) From: Krzysztof Kozlowski To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Stuart Yoder , Laurentiu Tudor , Abel Vesa , Shawn Guo , Sascha Hauer , Fabio Estevam , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , Wei Liu , Dexuan Cui , Bjorn Helgaas , Bjorn Andersson , Mathieu Poirier , Vineeth Vijayan , Peter Oberparleiter , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Andy Gross , Srinivas Kandagatla , Mark Brown , "Michael S. Tsirkin" , Jason Wang , linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, NXP Linux Team , linux-arm-kernel@lists.infradead.org, linux-hyperv@vger.kernel.org, linux-pci@vger.kernel.org, linux-remoteproc@vger.kernel.org, linux-s390@vger.kernel.org, linux-arm-msm@vger.kernel.org, alsa-devel@alsa-project.org, linux-spi@vger.kernel.org, virtualization@lists.linux-foundation.org, Linus Torvalds Cc: Rasmus Villemoes , Krzysztof Kozlowski Subject: [PATCH v3 02/11] amba: Use driver_set_override() instead of open-coding Date: Sun, 27 Feb 2022 14:52:05 +0100 Message-Id: <20220227135214.145599-3-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220227135214.145599-1-krzysztof.kozlowski@canonical.com> References: <20220227135214.145599-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org Use a helper for seting driver_override to 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 --- drivers/amba/bus.c | 28 ++++------------------------ include/linux/amba/bus.h | 7 ++++++- 2 files changed, 10 insertions(+), 25 deletions(-) diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c index e1a5eca3ae3c..9dffa17f50c0 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 6c7f47846971..7c703cb7a3cf 100644 --- a/include/linux/amba/bus.h +++ b/include/linux/amba/bus.h @@ -70,7 +70,12 @@ 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 Sun Feb 27 13:52:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 12761742 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D31C6C433FE for ; Sun, 27 Feb 2022 13:53:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231362AbiB0Nxp (ORCPT ); Sun, 27 Feb 2022 08:53:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231313AbiB0Nxg (ORCPT ); Sun, 27 Feb 2022 08:53:36 -0500 Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9454E09F for ; Sun, 27 Feb 2022 05:52:53 -0800 (PST) Received: from mail-lf1-f69.google.com (mail-lf1-f69.google.com [209.85.167.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 9CA5441273 for ; Sun, 27 Feb 2022 13:52:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645969967; bh=lHEHPtP6JAM6zCrRNeDTlRy/WZxSvWGZvNHgREr2xAI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=BddtnmlhtW0yc8uxzOxEKoC5UbmYRRVe65EIYowMdSJ1/yEdOzc01mJTayNtJOg/B g1okumschZUbP8Rx2cEMt6GQZlNkvZggCRim12RA2wpqM1ENlzlqv3AjXUNdZLYn4K eBGIeLnt1/PD+qgcmacUWduYJFsmbfUMEbHu11vSnCkkT1VX9uhpnuS7QDdPEjJ761 VSguCWJ58LVZYl8nyl0YGodaXmfCausJXCJ7NqIte9A6kRIVSQ7LveHc/LRPPIzb/Z v/f0lfgiqhnktGFkDD06D8EUjfMChY2m6n9FHd5HUQpVKjpqIq78nZ3tTRVMjw9YXp e8eSBaDPfbk1Q== Received: by mail-lf1-f69.google.com with SMTP id a5-20020ac25205000000b00443a34a9472so1393884lfl.15 for ; Sun, 27 Feb 2022 05:52:47 -0800 (PST) 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=lHEHPtP6JAM6zCrRNeDTlRy/WZxSvWGZvNHgREr2xAI=; b=cvyyJHVqKwqtfqHWxQY5jBbnspwk0CmxooIVwgbffexvB9b15k84nDfKW3YJVlT/4C O+KAB9EUroD59zp0xxxOCSG1jAU94BKaLgOtnuX2ZvIsvlgx/STLP0RFN0v69T864Jgr jBcRQGAQI6j4HQ6hWpPpVu3KZjiBySHg6FYGAN2oHu1AmvmG7m/NRp8gbexDEK6GAI9v qUHeZ5s5B3MARn5wPr9h0lCKiE2MV7RfBfbphqTJ/ltRFBgaYAc0XxT9XvvQUvwaJ+WF IXUTimBt0lkxN+FHvZN2EbKs7V8P95Agr57EZn096Ygiv38XvN57tiUOOpUhkujCj1we Sh5g== X-Gm-Message-State: AOAM532ffLegTG4B3yzZfueTu/GWHdgEEMMZhTZCnSaSL+/ZnUqkfZuo z58dURheob34QtMy4yAcH1DV/j0u4qSkDD0WxkAQOat1P9EciiLS7YtvaG8QgLkgRGo7pOpR7tw Xcf3zID0ryZpuRsqcgpccHTzyrrbHA3Yx9A5DO81+xIfZD10= X-Received: by 2002:a17:906:d10c:b0:6cd:4aa2:cd62 with SMTP id b12-20020a170906d10c00b006cd4aa2cd62mr12751224ejz.229.1645969956021; Sun, 27 Feb 2022 05:52:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJyXq+ZARVgwx9GQqR/xqmr4FidvI0jbXs/SPWVteyhvLCXz3Udlc0TuaU2TzyIf2JoyZYkY6w== X-Received: by 2002:a17:906:d10c:b0:6cd:4aa2:cd62 with SMTP id b12-20020a170906d10c00b006cd4aa2cd62mr12751178ejz.229.1645969955744; Sun, 27 Feb 2022 05:52:35 -0800 (PST) Received: from localhost.localdomain (xdsl-188-155-181-108.adslplus.ch. [188.155.181.108]) by smtp.gmail.com with ESMTPSA id r22-20020a17090638d600b006d584aaa9c9sm3393333ejd.133.2022.02.27.05.52.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Feb 2022 05:52:35 -0800 (PST) From: Krzysztof Kozlowski To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Stuart Yoder , Laurentiu Tudor , Abel Vesa , Shawn Guo , Sascha Hauer , Fabio Estevam , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , Wei Liu , Dexuan Cui , Bjorn Helgaas , Bjorn Andersson , Mathieu Poirier , Vineeth Vijayan , Peter Oberparleiter , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Andy Gross , Srinivas Kandagatla , Mark Brown , "Michael S. Tsirkin" , Jason Wang , linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, NXP Linux Team , linux-arm-kernel@lists.infradead.org, linux-hyperv@vger.kernel.org, linux-pci@vger.kernel.org, linux-remoteproc@vger.kernel.org, linux-s390@vger.kernel.org, linux-arm-msm@vger.kernel.org, alsa-devel@alsa-project.org, linux-spi@vger.kernel.org, virtualization@lists.linux-foundation.org, Linus Torvalds Cc: Rasmus Villemoes , Krzysztof Kozlowski Subject: [PATCH v3 03/11] fsl-mc: Use driver_set_override() instead of open-coding Date: Sun, 27 Feb 2022 14:52:06 +0100 Message-Id: <20220227135214.145599-4-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220227135214.145599-1-krzysztof.kozlowski@canonical.com> References: <20220227135214.145599-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org Use a helper for seting driver_override to 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 --- 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 Sun Feb 27 13:52:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 12761741 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2680EC433FE for ; Sun, 27 Feb 2022 13:53:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231298AbiB0Nxj (ORCPT ); Sun, 27 Feb 2022 08:53:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231311AbiB0Nxf (ORCPT ); Sun, 27 Feb 2022 08:53:35 -0500 Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48D0513F0F for ; Sun, 27 Feb 2022 05:52:52 -0800 (PST) Received: from mail-lj1-f199.google.com (mail-lj1-f199.google.com [209.85.208.199]) (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 D51B740296 for ; Sun, 27 Feb 2022 13:52:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645969969; bh=pRyoy0wYqVh1vMWkfgiwvfL+uC0PF+MUz+uOlTyWlM0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=VtSqodw296hHzS5Le9GXIUsO7GrmUwkFqj3exMhPtVmV2PH047f2xOl1p9qT9S5e7 yqhX0ft2Bon6HHKCotL7GaQKyEQ6T5KaCLoefMTOo3J5LEIEsYmdcAmAJMh2yaFLng xeXC2UY5JC3Q+iF1qNLEskBDa+wdKta6w1xYGpvefmmrHjBbjF/RiXsWvNqEMOM3d3 /CR5GmOJiBnPLqWvF4g37HBJCbR8esAAhV8L9KON1yk+dRXpqHMbi+fJTr/zPycn0N D+SoBsKAnZAuGiv1n0lZmi5TZaDzlsexwP03nUf5YqEHnSvs9iydM8rhRWnY5zNN8Z FBi4bLw7tRBRQ== Received: by mail-lj1-f199.google.com with SMTP id v5-20020a2ea605000000b00246322afc8cso4466932ljp.4 for ; Sun, 27 Feb 2022 05:52:49 -0800 (PST) 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=pRyoy0wYqVh1vMWkfgiwvfL+uC0PF+MUz+uOlTyWlM0=; b=ylrUs0cgpU6P9QwL2icTM+UnUcMOwYXx2dzzxKVhoyvyAL/SmksQO6qXP+VMCdmY+g Svl8CjsaR+LcgXRAuLwVVXfx3PGkyu1kur47BBjk0ismlcgZEWMM4XRBUW6Is2tPzOEy 9PCeupG3iqE434R15nfFlgiUvoxLa9Z6NuQnCLwfEA/V3mny7WzKX6JwmWijUzXzb0l7 2ZW36a1iWk0LVVU+zI7Qmn/0dChQe3IYqMAbedIQlRaO3O4bqp2R4gQrThX+hYatenE+ kwRZY2uwzh8UvrOfWjipO3W8QMebObHxS80AVkJ22gbDUkKB4eY0WvX1wAZEEZfM+A6C HsLA== X-Gm-Message-State: AOAM532bhNTetvrApeuA98eWfZyO1uJaV0Elf4I/8XZobnyFpN70YSkw 63s1SAFtEFTRHfHCSk8LXToYTi2HEUjF+8NEYDu+Xe/17tWG0igXF1OxQMY0QebSvCvsALmli8+ j4m9O4NrjiFGfO2Di2/KHPa97dN1GJ8IFjf9L1tcMqzIvf3I= X-Received: by 2002:a05:6402:1a55:b0:410:a4b4:2a9d with SMTP id bf21-20020a0564021a5500b00410a4b42a9dmr15356221edb.45.1645969957664; Sun, 27 Feb 2022 05:52:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJxMCUVqX+GQTf3SH7q4WKAqDIKbuRWwlLyTqLEz2lVHwA8GB9LJKefEiix56LpqtlrzGflkbw== X-Received: by 2002:a05:6402:1a55:b0:410:a4b4:2a9d with SMTP id bf21-20020a0564021a5500b00410a4b42a9dmr15356182edb.45.1645969957475; Sun, 27 Feb 2022 05:52:37 -0800 (PST) Received: from localhost.localdomain (xdsl-188-155-181-108.adslplus.ch. [188.155.181.108]) by smtp.gmail.com with ESMTPSA id r22-20020a17090638d600b006d584aaa9c9sm3393333ejd.133.2022.02.27.05.52.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Feb 2022 05:52:36 -0800 (PST) From: Krzysztof Kozlowski To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Stuart Yoder , Laurentiu Tudor , Abel Vesa , Shawn Guo , Sascha Hauer , Fabio Estevam , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , Wei Liu , Dexuan Cui , Bjorn Helgaas , Bjorn Andersson , Mathieu Poirier , Vineeth Vijayan , Peter Oberparleiter , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Andy Gross , Srinivas Kandagatla , Mark Brown , "Michael S. Tsirkin" , Jason Wang , linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, NXP Linux Team , linux-arm-kernel@lists.infradead.org, linux-hyperv@vger.kernel.org, linux-pci@vger.kernel.org, linux-remoteproc@vger.kernel.org, linux-s390@vger.kernel.org, linux-arm-msm@vger.kernel.org, alsa-devel@alsa-project.org, linux-spi@vger.kernel.org, virtualization@lists.linux-foundation.org, Linus Torvalds Cc: Rasmus Villemoes , Krzysztof Kozlowski Subject: [PATCH v3 04/11] hv: Use driver_set_override() instead of open-coding Date: Sun, 27 Feb 2022 14:52:07 +0100 Message-Id: <20220227135214.145599-5-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220227135214.145599-1-krzysztof.kozlowski@canonical.com> References: <20220227135214.145599-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org Use a helper for seting driver_override to 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 | 7 ++++++- 2 files changed, 10 insertions(+), 25 deletions(-) diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c index 12a2b37e87f3..a0ff4139c3d2 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..beea11874be2 100644 --- a/include/linux/hyperv.h +++ b/include/linux/hyperv.h @@ -1257,7 +1257,12 @@ 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 Sun Feb 27 13:52:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 12761740 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2B377C433EF for ; Sun, 27 Feb 2022 13:53:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231345AbiB0Nxh (ORCPT ); Sun, 27 Feb 2022 08:53:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231300AbiB0Nxa (ORCPT ); Sun, 27 Feb 2022 08:53:30 -0500 Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73B9F13F40 for ; Sun, 27 Feb 2022 05:52:52 -0800 (PST) Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.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-1.canonical.com (Postfix) with ESMTPS id 313D9402DD for ; Sun, 27 Feb 2022 13:52:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645969970; bh=ovOgd1VJlKyRzMY+TlP34IMSMGHGw8uakjQlL885+iI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=fN2t5/EE2yhwXd0uArW+F/K+cHueu8APZJPBMtBVxrSBENxOvTULI4qFYk82aWCCO RwF9mhHhUtr7RoOqNoXxdDAOzRpNF3+zgIYyHBVEsZuJ4tqDRbdb15GjJV2Jx2USRZ fr7V489qhuLTKsO+/Z3M5XWyXDqDNVqpd7yyPIlWm2N2rT4busKiowhLeo3fkF1Xdl 15gDTK6fxcKMkVY+8BdJsqeIDYRsIaIimLpuV8qWBgCG46oY2Jqy0vhDys/p7oTbVj wMETxWlEsvzi7+DUhi8ZHuQbd7aa7+pDDaf1HZzygG0DuUOy/mrrvRex/RKXo6IqH+ psweF0VmAgKCg== Received: by mail-ed1-f72.google.com with SMTP id l14-20020aa7cace000000b003f7f8e1cbbdso4234957edt.20 for ; Sun, 27 Feb 2022 05:52:50 -0800 (PST) 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=ovOgd1VJlKyRzMY+TlP34IMSMGHGw8uakjQlL885+iI=; b=YF476oohFrCA5ufRtPL2y9i54J7pjhXyfte1Wcrs+Zw9SNXgmj2eWhfqx7unlxzLmv oQvKxS/0lnq4TgeIflvHnKQ89Zm6aZ+oSwNWmFAOsgeVrxhxz4IU1QB5QG+H5uXN3ORe VT8qtcaOdrjG/sEt0AXGkUE1cNdBgWaNXrhJDkziBMMXong/X098D0pIyLqnLKJt1Ixx PuL2QXN6hpDpbnW6deV9qKahY5F+tn++DHdVfkz8n+zKw4jSFEqr7vvQOZo0IlcdHE22 uV6AoGgm7oVyZGDZUN8R9E9zIDo0WCRgxplOaySFTlzUpzRFhoQu0dXGovoCliW/M3En bugg== X-Gm-Message-State: AOAM530Lu1vAlWLLkMRsaETq2dD9PRB1QR42CpwUFJOumhOIMCaWJvtG aVEs5c2KDKOzBRQZW2kPpO/8BQJ5RE2KJAPCoSR1Lr2BWVBSk+pJ4Djp1pwWaGzRwtds8T+I2IY n7LEvuT7IzWtsvGCOgfxHgdDAuKLai31wjNS/tpHwBgFs89s= X-Received: by 2002:a17:906:82cf:b0:6d0:3d6:8f27 with SMTP id a15-20020a17090682cf00b006d003d68f27mr11873369ejy.236.1645969959551; Sun, 27 Feb 2022 05:52:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJwaPeLTnbLCXr36eOWjnDy8E4LI71/jJS3zMt9CSPHhfhuyTLYqyLKvSg58uZ5j7Z3tq7CVSw== X-Received: by 2002:a17:906:82cf:b0:6d0:3d6:8f27 with SMTP id a15-20020a17090682cf00b006d003d68f27mr11873353ejy.236.1645969959366; Sun, 27 Feb 2022 05:52:39 -0800 (PST) Received: from localhost.localdomain (xdsl-188-155-181-108.adslplus.ch. [188.155.181.108]) by smtp.gmail.com with ESMTPSA id r22-20020a17090638d600b006d584aaa9c9sm3393333ejd.133.2022.02.27.05.52.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Feb 2022 05:52:38 -0800 (PST) From: Krzysztof Kozlowski To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Stuart Yoder , Laurentiu Tudor , Abel Vesa , Shawn Guo , Sascha Hauer , Fabio Estevam , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , Wei Liu , Dexuan Cui , Bjorn Helgaas , Bjorn Andersson , Mathieu Poirier , Vineeth Vijayan , Peter Oberparleiter , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Andy Gross , Srinivas Kandagatla , Mark Brown , "Michael S. Tsirkin" , Jason Wang , linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, NXP Linux Team , linux-arm-kernel@lists.infradead.org, linux-hyperv@vger.kernel.org, linux-pci@vger.kernel.org, linux-remoteproc@vger.kernel.org, linux-s390@vger.kernel.org, linux-arm-msm@vger.kernel.org, alsa-devel@alsa-project.org, linux-spi@vger.kernel.org, virtualization@lists.linux-foundation.org, Linus Torvalds Cc: Rasmus Villemoes , Krzysztof Kozlowski Subject: [PATCH v3 05/11] PCI: Use driver_set_override() instead of open-coding Date: Sun, 27 Feb 2022 14:52:08 +0100 Message-Id: <20220227135214.145599-6-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220227135214.145599-1-krzysztof.kozlowski@canonical.com> References: <20220227135214.145599-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org Use a helper for seting driver_override to 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 --- drivers/pci/pci-sysfs.c | 28 ++++------------------------ include/linux/pci.h | 7 ++++++- 2 files changed, 10 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 8253a5413d7c..5c00a8aebdf9 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -516,7 +516,12 @@ 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 Sun Feb 27 13:52:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 12761737 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4C288C433EF for ; Sun, 27 Feb 2022 13:52:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231283AbiB0Nx3 (ORCPT ); Sun, 27 Feb 2022 08:53:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231246AbiB0Nx0 (ORCPT ); Sun, 27 Feb 2022 08:53:26 -0500 Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 058E2E09F for ; Sun, 27 Feb 2022 05:52:49 -0800 (PST) Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.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-1.canonical.com (Postfix) with ESMTPS id DBA2A40608 for ; Sun, 27 Feb 2022 13:52:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645969963; bh=kn+qF0tdCo1etTHWEFOqoxtrhJ+rC4czu2ZZy5+SihI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=WlQEnPKIEePgugSx9iUYOn0DTmnQ+d7BtOIg4MGaZ+9cGE5YCqkk8Ofshq7hBm9Tr FLW6tnN5BgDuLs6McmJLswvsUbjdaPITe+HzA3UDzCe0JdLfeqhzLrFKlAQIX2QlmW D6f/l3UX0Szlk1hEA9r+jNp/m9IoLjR3gtKjVb0JP8HG6LY48++sIs7rLwjj2gVz2V /GQQMSU5qDA1VJM3tnsSk7LqH3riSbdq54vvrybAxGgsVpga4Sn+wmlGQ/SoCPF7hk uHoLl/yrkSqYCVNFYZ9UvvYPUD8jl5LWfGmD7FdK56ktalmwzFJNN2GCXWfVgoN/rs ZsRgk3vKodZ2A== Received: by mail-ed1-f69.google.com with SMTP id f9-20020a0564021e8900b00412d0a6ef0dso4242811edf.11 for ; Sun, 27 Feb 2022 05:52:43 -0800 (PST) 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=kn+qF0tdCo1etTHWEFOqoxtrhJ+rC4czu2ZZy5+SihI=; b=YeFT1GbhF8XasEGgWaJn/838guusnloGueAQy/x4DbLEbwdApd7uIYmRzh+VqsTQuK 6C68BSHTiPJp6s1tmc1I78pbT1pKkix2dKTzFrHUgAJVeaQuJiNBIk5jtsa4P0MVgkgo rA2YLqsIpgNsogV8hLEXHzh2VarABkGdoo8nPMWcr98lmk4OlOx9NJY+vDBzSrdpL3KB n9Pbv3M54n3c22jpsqG8zRaMXoYiEmi3vDzYmtApxNLflKxOYqRcV3rLN9BA8kCVXH6+ UdUw4q/FTi4zz6r7WF0AVltLheFf+VjgFg+5djgmKVOpWCNomnF5Ii5G4cb23RS9DY9Y Ap4A== X-Gm-Message-State: AOAM532ad2mXH9cE0EwC1xiGgaTvNsBGKFNg1IVCQKJBAzZirbhH+fj4 ylNcxkR/joJW63tcFwpt3iu5jcafsK1LrKkIDd9wNnW+5G4zsML86vvzl5yAo+I+croM5q/Hr1g WmfuqW/FdR13uIec/Cq8AeufM/KGBqaHtDlxpG3pcUSNdPwQ= X-Received: by 2002:aa7:c4da:0:b0:410:bb1d:8232 with SMTP id p26-20020aa7c4da000000b00410bb1d8232mr15075918edr.333.1645969961199; Sun, 27 Feb 2022 05:52:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJyhg/i5aHofZaz+ahzc6dFTcb8xbpOjhh0OtL6Jhkm85pFdhXbdMsjLVRzYgEWWn1QmpSdqKg== X-Received: by 2002:aa7:c4da:0:b0:410:bb1d:8232 with SMTP id p26-20020aa7c4da000000b00410bb1d8232mr15075900edr.333.1645969960978; Sun, 27 Feb 2022 05:52:40 -0800 (PST) Received: from localhost.localdomain (xdsl-188-155-181-108.adslplus.ch. [188.155.181.108]) by smtp.gmail.com with ESMTPSA id r22-20020a17090638d600b006d584aaa9c9sm3393333ejd.133.2022.02.27.05.52.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Feb 2022 05:52:40 -0800 (PST) From: Krzysztof Kozlowski To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Stuart Yoder , Laurentiu Tudor , Abel Vesa , Shawn Guo , Sascha Hauer , Fabio Estevam , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , Wei Liu , Dexuan Cui , Bjorn Helgaas , Bjorn Andersson , Mathieu Poirier , Vineeth Vijayan , Peter Oberparleiter , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Andy Gross , Srinivas Kandagatla , Mark Brown , "Michael S. Tsirkin" , Jason Wang , linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, NXP Linux Team , linux-arm-kernel@lists.infradead.org, linux-hyperv@vger.kernel.org, linux-pci@vger.kernel.org, linux-remoteproc@vger.kernel.org, linux-s390@vger.kernel.org, linux-arm-msm@vger.kernel.org, alsa-devel@alsa-project.org, linux-spi@vger.kernel.org, virtualization@lists.linux-foundation.org, Linus Torvalds Cc: Rasmus Villemoes , Krzysztof Kozlowski Subject: [PATCH v3 06/11] s390: cio: Use driver_set_override() instead of open-coding Date: Sun, 27 Feb 2022 14:52:09 +0100 Message-Id: <20220227135214.145599-7-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220227135214.145599-1-krzysztof.kozlowski@canonical.com> References: <20220227135214.145599-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org Use a helper for seting driver_override to 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 | 7 ++++++- drivers/s390/cio/css.c | 28 ++++------------------------ 2 files changed, 10 insertions(+), 25 deletions(-) diff --git a/drivers/s390/cio/cio.h b/drivers/s390/cio/cio.h index 1cb9daf9c645..e110c10613e8 100644 --- a/drivers/s390/cio/cio.h +++ b/drivers/s390/cio/cio.h @@ -103,7 +103,12 @@ 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 Sun Feb 27 13:53: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: 12761744 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 68167C3525A for ; Sun, 27 Feb 2022 13:53:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231348AbiB0Ny0 (ORCPT ); Sun, 27 Feb 2022 08:54:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231210AbiB0NyZ (ORCPT ); Sun, 27 Feb 2022 08:54:25 -0500 Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49E6B13E3A for ; Sun, 27 Feb 2022 05:53:48 -0800 (PST) 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 2B2673F02B for ; Sun, 27 Feb 2022 13:53:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645970027; bh=qpFiz05rVbRuRAHN9hg8SmLpkD4Xh7SLbxYijfSgBwA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=i8TO3Wia8Ibg2o68tBDm9z9M2fsBJ/MJhIhhZPTETElHB760xFVWPrscG6IZ/wUSv M/SlRjyCadBNEsKuofMVoMrwPu4ZXUG/RR1lq5rNA5Zt++i53lMWQ1lrD9b2z08GH5 LTxlmpEDmGJdXZelNLRh7TeLwp8Ty+LpB/LE+m4WLbNde03MgOy/fZ2jshEh2J8Woi iYv8/+dhZw78px9UvkkxCMEDTd32df8VXMqijE+jlMm7vizyw+76TULuJltB/oxhs2 nDko+BfKkTfRyDV13ehKLCGZ680jYq1CnscgiVSkHBz8l34OA6wp8womknSk8AtoYG iQKQYTp6UXRXQ== Received: by mail-wm1-f70.google.com with SMTP id c62-20020a1c3541000000b003815245c642so1227077wma.6 for ; Sun, 27 Feb 2022 05:53:47 -0800 (PST) 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=qpFiz05rVbRuRAHN9hg8SmLpkD4Xh7SLbxYijfSgBwA=; b=gpsFfeNmFwDxEHK0PX7GrFfhxVzdQz/XuYF5hmscTUvGKVylVsUTEZBocUyyyE/6IC MwsJAQs0BnC0/MGy7erwhtZw6v82ZNvqkJ9ql3cg0sfViN+SmapXo3Wbb9vdWUkv8iFT pLVPKao1jWCFOMBi4e2SfbPHJGbEp3gVLB4hm2rnw1mnoUVTwpvjmmgQYYfZ2A5vP574 nYKaMt4YjxMUggH9t64nFXhY5Bg0Fjl1FDzO25hIS1LfJuGVduu5bU9ykv6EVzxcVmKR SQXgg71kCcBV2ISExrUtc3YdU5aTD0thx/Snw8qy+bargkbGJPPPBHzISLeUTY/z2CYu J6lQ== X-Gm-Message-State: AOAM531Zh8OLFtGLY8Dpd5omxVppnEkxetZecz6F/xiBbVovxMIdgBCZ ZJru+5qzOsy9bAbG5T4ylqJ8cU3JzAoK+XOUMKduoW7M10e1YdR74uc4FTN1Y7FMCJr1JB9dlYo fRzR7XDEqV0iwn14FNtBFaHLqtFOjdZ5R9H7CxrZ/LZxAauI= X-Received: by 2002:aa7:d98a:0:b0:410:b844:7889 with SMTP id u10-20020aa7d98a000000b00410b8447889mr15100915eds.109.1645970015742; Sun, 27 Feb 2022 05:53:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJyhO9Sv0dF420J0f9IZ/pCEaONwOixtXPt4DqHWIJWIfdwGeQCrhRg50N3SHeq1oP4tMC2tSg== X-Received: by 2002:aa7:d98a:0:b0:410:b844:7889 with SMTP id u10-20020aa7d98a000000b00410b8447889mr15100871eds.109.1645970015533; Sun, 27 Feb 2022 05:53:35 -0800 (PST) Received: from localhost.localdomain (xdsl-188-155-181-108.adslplus.ch. [188.155.181.108]) by smtp.gmail.com with ESMTPSA id w11-20020a056402128b00b00412ec3f5f74sm4600760edv.62.2022.02.27.05.53.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Feb 2022 05:53:34 -0800 (PST) From: Krzysztof Kozlowski To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Stuart Yoder , Laurentiu Tudor , Abel Vesa , Shawn Guo , Sascha Hauer , Fabio Estevam , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , Wei Liu , Dexuan Cui , Bjorn Helgaas , Bjorn Andersson , Mathieu Poirier , Vineeth Vijayan , Peter Oberparleiter , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Andy Gross , Srinivas Kandagatla , Mark Brown , "Michael S. Tsirkin" , Jason Wang , linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, NXP Linux Team , linux-arm-kernel@lists.infradead.org, linux-hyperv@vger.kernel.org, linux-pci@vger.kernel.org, linux-remoteproc@vger.kernel.org, linux-s390@vger.kernel.org, linux-arm-msm@vger.kernel.org, alsa-devel@alsa-project.org, linux-spi@vger.kernel.org, virtualization@lists.linux-foundation.org, Linus Torvalds Cc: Rasmus Villemoes , Krzysztof Kozlowski Subject: [PATCH v3 07/11] spi: Use helper for safer setting of driver_override Date: Sun, 27 Feb 2022 14:53:25 +0100 Message-Id: <20220227135329.145862-1-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220227135214.145599-1-krzysztof.kozlowski@canonical.com> References: <20220227135214.145599-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org Use a helper for seting driver_override to reduce amount of duplicated code. Signed-off-by: Krzysztof Kozlowski --- 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 4599b121d744..9d0b11017741 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -72,29 +72,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 7ab3fed7b804..f99bbb20dd4b 100644 --- a/include/linux/spi/spi.h +++ b/include/linux/spi/spi.h @@ -136,6 +136,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_gpio: LEGACY: gpio number of the chipselect line (optional, -ENOENT when * not using a GPIO line) use cs_gpiod in new drivers by opting in on * the spi_master. From patchwork Sun Feb 27 13:53: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: 12761745 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 02219C4707A for ; Sun, 27 Feb 2022 13:53:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231179AbiB0Ny1 (ORCPT ); Sun, 27 Feb 2022 08:54:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231355AbiB0Ny0 (ORCPT ); Sun, 27 Feb 2022 08:54:26 -0500 Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF29113FB3 for ; Sun, 27 Feb 2022 05:53:49 -0800 (PST) Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.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 600913FCAF for ; Sun, 27 Feb 2022 13:53:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645970028; bh=npGNvoQmcQXzOf9MUvG7bOfkjnwx60Xk35PbEgCfPxw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TuSSqqLER80YcA1/RpVOJ2K5WL+/AG4UvX1GCjPhRt8igN7+egU3VdFqP01lBdTto bi/nxScJF30ylROyvEEDzmBsUOUKH6InN4ULr93fj2AJr3syOgPXbfaXz7M3/N9LIW hCMJbtjL2yP1tFFrmDIQ6Bi4VXsbkm6FTvIw0GqWZwMiQR4GVHTXM0Ve2Am0Xm3l1g 6opBlecxSjQoQZNWNbwBvD0FQY727Z2YQhARzYOUQVp8cpRLjYiV0QW/DN35YpzwmE GjrWXp3FtU8dOd1JGX00qfI4gOAsZqsOzTy9k27FjhYMmgfo+qL1uRfM4ltpZI6w58 WrGnFMGNOFueA== Received: by mail-ed1-f69.google.com with SMTP id h17-20020a05640250d100b004133863d836so4272159edb.0 for ; Sun, 27 Feb 2022 05:53:48 -0800 (PST) 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=npGNvoQmcQXzOf9MUvG7bOfkjnwx60Xk35PbEgCfPxw=; b=QEb7/ORxitJFZ/3vpUzRqhK6LrvNfBC2cpNfxHtJARdCprOeE2446UfgIeKGve7KaS bwhWeVpeNxXtihoSnNrR7xEsG3r9sv36m+2eqV0VBn/PS4wJY/TLVYtvPebH62Pu+SJL CDIURv6mvNxmSXDrTQp3kLAhi1dECqk8hyKpnaBAsJ8315bE6eGzHP5iCjz9jDMUon8q RmH//rfidEtjsmOfFUUhyxhzS59VTNXW4TxUmbCmSxJ2+w1ui6ksx08zaOUeTHWgRML2 i0rzDGu1g4dutJ0pFfU0sen75ThUdC45doCN9OREUpNhIQGgcMtaxVIMksEiLEZ7hk8O 5JKw== X-Gm-Message-State: AOAM530k94aq88sjR4xZc6hEK7chUeLwJKJxaOGuQU/JVhBxsMXasXpd QEUM2oVbtTig2cfRE3+v0TUp7t3X/Ay1ZNyLZx+t28jGIiLbfJWqMdjof12TbUJrG98BEEn7giN Mr1gksZuX/exTkgZkyIe7fRt8oeBIELioH6XQ1RIgQFyT700= X-Received: by 2002:aa7:d49a:0:b0:410:875c:e21b with SMTP id b26-20020aa7d49a000000b00410875ce21bmr15261506edr.357.1645970017417; Sun, 27 Feb 2022 05:53:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJzicu7l4IEwzqhlq2xIFoxdFytokSeMFkgjaEtpJW9Dl/uL3ibJtEoSzuA4VDSoAwu8n3nm0A== X-Received: by 2002:aa7:d49a:0:b0:410:875c:e21b with SMTP id b26-20020aa7d49a000000b00410875ce21bmr15261460edr.357.1645970017251; Sun, 27 Feb 2022 05:53:37 -0800 (PST) Received: from localhost.localdomain (xdsl-188-155-181-108.adslplus.ch. [188.155.181.108]) by smtp.gmail.com with ESMTPSA id w11-20020a056402128b00b00412ec3f5f74sm4600760edv.62.2022.02.27.05.53.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Feb 2022 05:53:36 -0800 (PST) From: Krzysztof Kozlowski To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Stuart Yoder , Laurentiu Tudor , Abel Vesa , Shawn Guo , Sascha Hauer , Fabio Estevam , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , Wei Liu , Dexuan Cui , Bjorn Helgaas , Bjorn Andersson , Mathieu Poirier , Vineeth Vijayan , Peter Oberparleiter , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Andy Gross , Srinivas Kandagatla , Mark Brown , "Michael S. Tsirkin" , Jason Wang , linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, NXP Linux Team , linux-arm-kernel@lists.infradead.org, linux-hyperv@vger.kernel.org, linux-pci@vger.kernel.org, linux-remoteproc@vger.kernel.org, linux-s390@vger.kernel.org, linux-arm-msm@vger.kernel.org, alsa-devel@alsa-project.org, linux-spi@vger.kernel.org, virtualization@lists.linux-foundation.org, Linus Torvalds Cc: Rasmus Villemoes , Krzysztof Kozlowski Subject: [PATCH v3 08/11] vdpa: Use helper for safer setting of driver_override Date: Sun, 27 Feb 2022 14:53:26 +0100 Message-Id: <20220227135329.145862-2-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220227135214.145599-1-krzysztof.kozlowski@canonical.com> References: <20220227135214.145599-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org Use a helper for seting driver_override to reduce amount of duplicated code. Signed-off-by: Krzysztof Kozlowski --- 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 9846c9de4bfa..2d924a89ce28 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 2de442ececae..89ec4e4d4cdc 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 Sun Feb 27 13:53: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: 12761746 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 07635C433EF for ; Sun, 27 Feb 2022 13:53:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230463AbiB0Ny2 (ORCPT ); Sun, 27 Feb 2022 08:54:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231299AbiB0NyW (ORCPT ); Sun, 27 Feb 2022 08:54:22 -0500 Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04B4314026 for ; Sun, 27 Feb 2022 05:53:44 -0800 (PST) Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.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 C7A083FCA5 for ; Sun, 27 Feb 2022 13:53:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645970021; bh=x+DOMuEjhXppqlmSDNC0RKdzUzslcBqDhsGS9OsoQS4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TVOVbta0ueT8ZRURaUSUSMpiCRWXCaUi2ZGIkk6uD7987ADPOR5ImN8CseFr1uncU lvz5fH+do659CaVP1MZQdPXe0YuNqBT1i6fg8rmzXDSLJm4/o/pd+7DNcIyAw8EWxt 2HhMlH1L397N8uP0NwnNY+SfZVkWlYDmLQ0i7u7qnCOIE4VJOGEchiQn+mXcDO+VFI 7guOPGBfMCgdfUXtG0e6qh4ggfA4WL6WANe/imQ4fPSNgZTeB+m5mbCWIL6dZEM4Jh U3Oj5Q+YNKSGnra0mxalKc/jPgcJbtAI0yRqnocGgl+0uR3ZX3BMcGHXnMd0OIZNcB xEG6pyVhMh1HQ== Received: by mail-ed1-f69.google.com with SMTP id l14-20020aa7cace000000b003f7f8e1cbbdso4235632edt.20 for ; Sun, 27 Feb 2022 05:53:41 -0800 (PST) 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=x+DOMuEjhXppqlmSDNC0RKdzUzslcBqDhsGS9OsoQS4=; b=PlIoqWHTpv4FeVX812scwNa/+8Zw0z+2NoBs2zh4beS3zRfYIlGndjtKBiG520wbuU t94EjxpmAur18sD7DnsYBfhXCyBhxoR2yHrrYbSJ5kajoXP/uIgDCct8MUU5FqrS0Gas lpUnkTv+Gr/UTyiPcT6ausgFFInOQa5/bEhgfxJPQXB7GiEX/cXLKymgzTt129mGSaSa 5MsxbgKRrTvbwIjXKJIXIaYXljAteZcBuc/xgu4oSFfV3+9OqPmFqiGXi5uGiyLMmqFL u/SXQi7JF0ytrpz4BPi5C6JPun17KdZL+/PwLk6nYrKwuy7clUhRjglT5UcJQs4hVwja U0hw== X-Gm-Message-State: AOAM532vf9eOpflv07j1/2cM4CQmunWStpmvTpDroeL9XnRbKuMAHzU2 RuTw58hvgaeUGbYaY96wrr4X1P2EJt5EytFv5bW6X88T7qUOoQIVkg6GiNaQrAncF6BMehx6TQB pwqwqxcV5bmVD3nd6r9b5YnOUAJUrtMf8cDh/7qUM+6B/ZIA= X-Received: by 2002:a17:906:354f:b0:6b4:1449:2d03 with SMTP id s15-20020a170906354f00b006b414492d03mr13078913eja.197.1645970019291; Sun, 27 Feb 2022 05:53:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJyLkm/ya1hWTxNWHY0owECzZBrknUNuVIsi2Y1TI9mIZSzwklvOz9AjjK7v7g0U5lSZuOzjqQ== X-Received: by 2002:a17:906:354f:b0:6b4:1449:2d03 with SMTP id s15-20020a170906354f00b006b414492d03mr13078900eja.197.1645970019102; Sun, 27 Feb 2022 05:53:39 -0800 (PST) Received: from localhost.localdomain (xdsl-188-155-181-108.adslplus.ch. [188.155.181.108]) by smtp.gmail.com with ESMTPSA id w11-20020a056402128b00b00412ec3f5f74sm4600760edv.62.2022.02.27.05.53.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Feb 2022 05:53:38 -0800 (PST) From: Krzysztof Kozlowski To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Stuart Yoder , Laurentiu Tudor , Abel Vesa , Shawn Guo , Sascha Hauer , Fabio Estevam , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , Wei Liu , Dexuan Cui , Bjorn Helgaas , Bjorn Andersson , Mathieu Poirier , Vineeth Vijayan , Peter Oberparleiter , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Andy Gross , Srinivas Kandagatla , Mark Brown , "Michael S. Tsirkin" , Jason Wang , linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, NXP Linux Team , linux-arm-kernel@lists.infradead.org, linux-hyperv@vger.kernel.org, linux-pci@vger.kernel.org, linux-remoteproc@vger.kernel.org, linux-s390@vger.kernel.org, linux-arm-msm@vger.kernel.org, alsa-devel@alsa-project.org, linux-spi@vger.kernel.org, virtualization@lists.linux-foundation.org, Linus Torvalds Cc: Rasmus Villemoes , Krzysztof Kozlowski , stable@vger.kernel.org Subject: [PATCH v3 09/11] clk: imx: scu: Fix kfree() of static memory on setting driver_override Date: Sun, 27 Feb 2022 14:53:27 +0100 Message-Id: <20220227135329.145862-3-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220227135214.145599-1-krzysztof.kozlowski@canonical.com> References: <20220227135214.145599-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.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 --- 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 Sun Feb 27 13:53: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: 12761747 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0EF87C433EF for ; Sun, 27 Feb 2022 13:54:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231438AbiB0Nyp (ORCPT ); Sun, 27 Feb 2022 08:54:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231395AbiB0Nye (ORCPT ); Sun, 27 Feb 2022 08:54:34 -0500 Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CCCBA1C936 for ; Sun, 27 Feb 2022 05:53:54 -0800 (PST) Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.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 A3A99407AB for ; Sun, 27 Feb 2022 13:53:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645970032; bh=Ittcal6Pd+WYY4FgdYnMj0oR0y7noG6anoPNpq8mwII=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=GE7ENpidT+a7WcTaerqO6+NejAupKyRUD6NJVuBPUKmwvhH+qT+x0aBL7kwJwpu85 LHikue2wWI0pNLxJ7xSlsREm4hCq07EBflHXpUbR58+LnJuy8jTjr7lxlSXJ4tnfUS 454tIgAEOAkmTQuU/SSl0HSULH2BflpTWbpj/n88wx6N7x1BGNKskf82+75FvD4X30 +/oMPO4PCKaZrhmtpVPLYcB1QpbefL4sHJ9SdLgYmJz/02HQSoNYgo/nmrR29O+h4C Xj5vhV7m3SfcUggW9J8QAZB5pwXhv+Q53AduN7OPHx/nDWBLHw2BY1S5izELeITLyv Tu65i4wga6jag== Received: by mail-ed1-f72.google.com with SMTP id y10-20020a056402358a00b00410deddea4cso4232414edc.16 for ; Sun, 27 Feb 2022 05:53:52 -0800 (PST) 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=Ittcal6Pd+WYY4FgdYnMj0oR0y7noG6anoPNpq8mwII=; b=WHQthjwWe8UQHMsisK9s9CULXI1SRhiDLO35AC6R9fCJp9QOwn6JBl3mw7ve2ajhNd ARYbViTVLt387DarQjm0Sjtyyu9JbecAFBFyZT+R0cDIrtrHYh0oUKGWYkykSyMc/1DG 5HXjQXf9ppxZsfyUUuHQpaj2HQMa46mxSSgV4ynyDsXvsf2r6mSAOtz8A+jh4bdY1Prq GacDWj7HxlgUu+m2P2fUoi+CpH+6GUoW32wpk5Pbrdu2FUvdHfLhf7YU67OpTlyeOHTl l0pR5eRpriwQJlHaWLc7qrNBtChXpRUE0Obm3vUu/LXBCaBuwpEY84A8uhcKPkZaCLjX TmJg== X-Gm-Message-State: AOAM531Ca9CLxsYGDo2qf/dUXjmtxqhrqtrRCYWQs0ZPdqqqMCwWsvvH h0DDUK28///hGrbtzmBtsxB76SISS+XDPHFVqZPVOHUxE8jqTYtuKuExBMdchyREO9So6v5Tr9d 3K/2F5PZkOMSWE2RNDWHkLvvXj3jgklN7ycKRZhnmkSGO/JM= X-Received: by 2002:a05:6402:42c6:b0:412:8cbc:8f3d with SMTP id i6-20020a05640242c600b004128cbc8f3dmr15364984edc.310.1645970020963; Sun, 27 Feb 2022 05:53:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJxGCAqzYcYv+6/2reZV+SOww6e12ONBNi9SinPyNgz1D+wg9pi5uHfXVkGat4zViryxXKoTAQ== X-Received: by 2002:a05:6402:42c6:b0:412:8cbc:8f3d with SMTP id i6-20020a05640242c600b004128cbc8f3dmr15364941edc.310.1645970020805; Sun, 27 Feb 2022 05:53:40 -0800 (PST) Received: from localhost.localdomain (xdsl-188-155-181-108.adslplus.ch. [188.155.181.108]) by smtp.gmail.com with ESMTPSA id w11-20020a056402128b00b00412ec3f5f74sm4600760edv.62.2022.02.27.05.53.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Feb 2022 05:53:40 -0800 (PST) From: Krzysztof Kozlowski To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Stuart Yoder , Laurentiu Tudor , Abel Vesa , Shawn Guo , Sascha Hauer , Fabio Estevam , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , Wei Liu , Dexuan Cui , Bjorn Helgaas , Bjorn Andersson , Mathieu Poirier , Vineeth Vijayan , Peter Oberparleiter , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Andy Gross , Srinivas Kandagatla , Mark Brown , "Michael S. Tsirkin" , Jason Wang , linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, NXP Linux Team , linux-arm-kernel@lists.infradead.org, linux-hyperv@vger.kernel.org, linux-pci@vger.kernel.org, linux-remoteproc@vger.kernel.org, linux-s390@vger.kernel.org, linux-arm-msm@vger.kernel.org, alsa-devel@alsa-project.org, linux-spi@vger.kernel.org, virtualization@lists.linux-foundation.org, Linus Torvalds Cc: Rasmus Villemoes , Krzysztof Kozlowski , stable@vger.kernel.org Subject: [PATCH v3 10/11] slimbus: qcom-ngd: Fix kfree() of static memory on setting driver_override Date: Sun, 27 Feb 2022 14:53:28 +0100 Message-Id: <20220227135329.145862-4-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220227135214.145599-1-krzysztof.kozlowski@canonical.com> References: <20220227135214.145599-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.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 7040293c2ee8..e5d9fdb81eb0 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 Sun Feb 27 13:53:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 12761743 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 18B77C433EF for ; Sun, 27 Feb 2022 13:53:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230322AbiB0NyX (ORCPT ); Sun, 27 Feb 2022 08:54:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231274AbiB0NyW (ORCPT ); Sun, 27 Feb 2022 08:54:22 -0500 Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7BC9213FB3 for ; Sun, 27 Feb 2022 05:53:44 -0800 (PST) Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.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-1.canonical.com (Postfix) with ESMTPS id 4896B3FCAC for ; Sun, 27 Feb 2022 13:53:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645970023; bh=bTICqCcdg5iJm3vxMOdY/WqtQRYU17qjxPM4LOVV5J8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=OujEerHnWCyDF7cX/5yrId98GeNHZv6gI/sMQgiLTHqu3Xyf3zeWSQlAsxqcIct76 jTG9GLXvjGvC2q4u+V4SVU0sFdMEQFS8eLVMHcfpIGnghkvjv5ddNJnLZAplIQgi2A yUPy4oJx88orAcm2PXKireQSd6p+jeQcYienaUHwoqGGJBzy9zqiq15P5mF6g9JF2H GYzhZk0H71pKDYwefwaC/XigcK4ioSk5+CMWTHdS3EWna7oikSNQMja6yF2Y8HTsVm HwMYJBCEBonvYC32SPhDqz/OepkxOoD9kMw7EnBYvSmdGuZctrxQU7ofntx539nxAY If6DCZRiLv0cA== Received: by mail-ed1-f71.google.com with SMTP id y13-20020aa7c24d000000b00411925b7829so4224676edo.22 for ; Sun, 27 Feb 2022 05:53:43 -0800 (PST) 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=bTICqCcdg5iJm3vxMOdY/WqtQRYU17qjxPM4LOVV5J8=; b=cIeQ0Di3D3HOXmn4B7abXuwnxStiQHKPAD7G+5zLRWFOyPVZDb732ZWpIdQwBkeES/ QqhnG9YC1bFsSOSJvGzWkQndWPaYaALRkcu6Pci6RG5XNJMBzg/HRJjnobW/kWO/iU7B gx0QQrPGQl0RhSQg/+DsPppKLN7HUK9b19zWfej/e6RfH6+ZDTrgE7831111HjozDfOv 9F5iH9ImtYLAiD1aiLm8JrJUNnYX9c92YpMSfcUIXU5rdjyH7CAqtFWQtocO4hv/WX0Q V7CwP9qEz1LbzXJCLFIfxl6uep1Bd3uc2KhAJpNYejmsCGt49UGVykoGOOV126+O/em6 uMFg== X-Gm-Message-State: AOAM532/aYvAM1hgGLCNzMj9GwM/q/07i0ktRdAuZDUikQyQjR5gEGR/ oCC8KiElWz/7n4dX3X6Yq7f2BVAKHE3sWKCDAZ/djLUNZKRd2iJnpKSxcv0lCRhVEvVsQl4aGB7 XfxhIpL513TrWw+cKKD4cSv1K/YQUMpCmr00UnKdGsHig+RM= X-Received: by 2002:a17:906:d8dc:b0:6cf:d1d1:db25 with SMTP id re28-20020a170906d8dc00b006cfd1d1db25mr12142687ejb.285.1645970022944; Sun, 27 Feb 2022 05:53:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJz4Gr3vRsze+QL2k9V58vZ4m4XpaQX7XqFritsjERMdwp7sW6hZpumhsWI+pYV6E4okAkDSDg== X-Received: by 2002:a17:906:d8dc:b0:6cf:d1d1:db25 with SMTP id re28-20020a170906d8dc00b006cfd1d1db25mr12142671ejb.285.1645970022727; Sun, 27 Feb 2022 05:53:42 -0800 (PST) Received: from localhost.localdomain (xdsl-188-155-181-108.adslplus.ch. [188.155.181.108]) by smtp.gmail.com with ESMTPSA id w11-20020a056402128b00b00412ec3f5f74sm4600760edv.62.2022.02.27.05.53.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Feb 2022 05:53:42 -0800 (PST) From: Krzysztof Kozlowski To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Stuart Yoder , Laurentiu Tudor , Abel Vesa , Shawn Guo , Sascha Hauer , Fabio Estevam , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , Wei Liu , Dexuan Cui , Bjorn Helgaas , Bjorn Andersson , Mathieu Poirier , Vineeth Vijayan , Peter Oberparleiter , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Andy Gross , Srinivas Kandagatla , Mark Brown , "Michael S. Tsirkin" , Jason Wang , linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, NXP Linux Team , linux-arm-kernel@lists.infradead.org, linux-hyperv@vger.kernel.org, linux-pci@vger.kernel.org, linux-remoteproc@vger.kernel.org, linux-s390@vger.kernel.org, linux-arm-msm@vger.kernel.org, alsa-devel@alsa-project.org, linux-spi@vger.kernel.org, virtualization@lists.linux-foundation.org, Linus Torvalds Cc: Rasmus Villemoes , Krzysztof Kozlowski , stable@vger.kernel.org Subject: [PATCH v3 11/11] rpmsg: Fix kfree() of static memory on setting driver_override Date: Sun, 27 Feb 2022 14:53:29 +0100 Message-Id: <20220227135329.145862-5-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220227135214.145599-1-krzysztof.kozlowski@canonical.com> References: <20220227135214.145599-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.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 | 13 +++++++++++-- drivers/rpmsg/rpmsg_ns.c | 14 ++++++++++++-- include/linux/rpmsg.h | 6 ++++-- 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/drivers/rpmsg/rpmsg_core.c b/drivers/rpmsg/rpmsg_core.c index d9e612f4f0f2..6e2bf2742973 100644 --- a/drivers/rpmsg/rpmsg_core.c +++ b/drivers/rpmsg/rpmsg_core.c @@ -397,7 +397,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 b1245d3ed7c6..31345d6e9a7e 100644 --- a/drivers/rpmsg/rpmsg_internal.h +++ b/drivers/rpmsg/rpmsg_internal.h @@ -92,10 +92,19 @@ int rpmsg_release_channel(struct rpmsg_device *rpdev, */ static inline int rpmsg_chrdev_register_device(struct rpmsg_device *rpdev) { + int ret; + strcpy(rpdev->id.name, "rpmsg_chrdev"); - rpdev->driver_override = "rpmsg_chrdev"; + ret = driver_set_override(&rpdev->dev, &rpdev->driver_override, + "rpmsg_chrdev", strlen("rpmsg_chrdev")); + if (ret) + return ret; + + ret = rpmsg_register_device(rpdev); + if (ret) + kfree(rpdev->driver_override); - return rpmsg_register_device(rpdev); + 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;