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: 12761713 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 0654EC433FE for ; Sun, 27 Feb 2022 13:53:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231325AbiB0Nxg (ORCPT ); Sun, 27 Feb 2022 08:53:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231285AbiB0Nx3 (ORCPT ); Sun, 27 Feb 2022 08:53:29 -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 2B79613E32 for ; Sun, 27 Feb 2022 05:52:51 -0800 (PST) Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.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 16F9F4060C for ; Sun, 27 Feb 2022 13:52:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645969964; bh=CdJmQ2T6u9FeKBCl3rxyT2dhiXMmAcmjIg9rruFo2ow=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nndBD8vo27cx5uFTuqy6q7BYyfNXDM1TSJ0Tq/mF4/y/ZmzQ9xf8ZX3WZj+cEBCws QpBdj/TZ6lRtRrXEgz+9U+3ji1j6fKtNnm2Yr5OTjh4HcPS9corTW7nSbC3kl5vevz gZvRVRHdaRvEblVJ/6D57ednQPt75U+3fExHArbCoFou1kmVe8zpaErOwlEpnz5F6S WFEQNm6oNeiA/EC/P6sH0hnaPP19IozqUv9EzaHPFLWBwUUnqlf4nlhbOOrNAe8bTH //yys3bEPyawfTP9Vvnxcg8CBlRykIsFjq8hLtKYO4cHSg4XfJOcubzeC2w2yHT3NA kRj+WSlIEwE5Q== Received: by mail-ed1-f70.google.com with SMTP id r9-20020a05640251c900b00412d54ea618so4216239edd.3 for ; Sun, 27 Feb 2022 05:52:44 -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=RMsLtk2hIM5kRHlqEWoMlu3PkNIr+tMx3N+46kl7JW8rUXQHtnixDKPYd8wsBGopy2 rOp9p9TKDWE9yW/0U5rnfN9ez20IthsmtXyph6bc4Xi9pptCOwfQ68jC2P+oLdjzLKBb 0mNsqNu42vmNALUKKvHRIh4tcNYLjIECOc6463tbDi9CwNZ23y8GNz+padxp0k7yl5gq /9C72x88L7OZv/Kopm1GlXa0gOeDw3p6Jx0a3OxOlAKrcZl+P/nB3pZUpEi2RUwaUH0N u6TPT/DUwJDwC9r+CSwIgHxtddiBtfZy7f4qAlt6Jpp+XYIk27EmsmrulybJaXKwCx3G 3b8A== X-Gm-Message-State: AOAM532q5Zo9Vj+E1+aZKyae5B1XQcPSBoNEOZvz8PTKkfiv6bh4qg4A dzPJ0pQU5mDgHgA3a00DAfmLS3X2IQ06RbxlNN1blGcvtYQu1sWBL7mQLgyStMk5DwKZXWF36vP IaJIZPVmxkq2Z6l9cJrEVM7FNcb+5FFjUsq6RhBib+u8= X-Received: by 2002:a05:6402:369a:b0:413:81b5:7b64 with SMTP id ej26-20020a056402369a00b0041381b57b64mr9401236edb.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-arm-msm@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: 12761715 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 C7024C433F5 for ; Sun, 27 Feb 2022 13:53:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231357AbiB0Nxj (ORCPT ); Sun, 27 Feb 2022 08:53:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231281AbiB0Nxf (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 2B8EF13E38 for ; Sun, 27 Feb 2022 05:52:51 -0800 (PST) Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.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 C3B743F1D9 for ; Sun, 27 Feb 2022 13:52:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645969965; bh=m4/zffFNkZQ1c8QkZX27EHIqdt+D+lrYYYcC+6RBnKM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=g+3sG+3FOc1gTcd0l1Bw6HIgI06GXD998GudvWujuD2lwF5SfwQX6cCAqa0fqMZb3 b+uM68/zoEJToLHeUlL3q23wsYEsorD+SQz53pxC7zFeZcR84q8CNANDsp5DM0OCht VQvJn7wHO5NHXO6Nav1a4VWlrKQhr1RH4yvHkaWI7Lgl0/iry5OKNK4CWm6CDuDMfm 8onDb7yngdMBVrhlKi61CP6ip5OCSMW03XVoEe/azE/z9FYiWKWntElbyB9Tpb2x5L N8sSaVLrneYPOkXYhxwdR7LKMEWY+OyVcWj3ke3xasG8Uk0EXCbmZgpa+GewCTBL2s NRWv2Cc+bq3Fg== Received: by mail-wm1-f72.google.com with SMTP id 10-20020a1c020a000000b0037fae68fcc2so4907795wmc.8 for ; Sun, 27 Feb 2022 05:52:45 -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=uuVAEWaT2MFknHOoIlk+ihfHw7e1KyRg8YFAR+/m6XEfVDD68h6c5GeGiL8wlQdcFE 3Cs2kMEgcmTcsgp2YAk44q1F1uHLz9+ffOEXLf1pgorolEGsDPhblxNHkEBnjiEkDYqb i31fEtzmofrYVAju1+9smXsn6ESDVX10l0YaMdc1VWj7A44TDkCeL/L/warapqRTx19D rM3VJwBupaapPCDIhzY0eeiCk+/ojafHMBQR2mSSBiKrpLdW94CUSyIwg9HVMC9uMQg6 O7aMyDgtP4hB0+bn8BAXZJXE8pDezExlxE4vIeHC/ekW2xHg/MZpRoN78/A80numUOFo UYrQ== X-Gm-Message-State: AOAM533X7oAHPgIhkaCE8IueVWQoE5DEIT9QtDAC69ofVVdPq+w7QG8L J8UcFDUHYqIXO6ec3B2RD0HfAXJEgKY7NaRHo8lnjupNqbGLCAadSZ/I2SQvXmKU6YhJDs/t9Dp 9gu2B7Jk4SFwjXhvxzEcVmvh9uN+rGgHhAVJbDxKbX8E= X-Received: by 2002:a17:906:4a09:b0:6d0:7f19:d738 with SMTP id w9-20020a1709064a0900b006d07f19d738mr12036167eju.76.1645969954376; 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-arm-msm@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: 12761714 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 67879C43217 for ; Sun, 27 Feb 2022 13:53:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231341AbiB0Nxh (ORCPT ); Sun, 27 Feb 2022 08:53:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231298AbiB0Nxa (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 2BB7E13E3A for ; Sun, 27 Feb 2022 05:52:51 -0800 (PST) Received: from mail-lj1-f200.google.com (mail-lj1-f200.google.com [209.85.208.200]) (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 87C163FCA8 for ; Sun, 27 Feb 2022 13:52:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645969968; bh=lHEHPtP6JAM6zCrRNeDTlRy/WZxSvWGZvNHgREr2xAI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=aeQIBnGYF2OkNoGja7ScL7ajAv+MiRMDCVONDGIrDMGs0KEpIQJQfej6Rody70N0c vJq8r6sH0vmotU/T+BeJYW+HzUoyp5lCg2TTiTyGGhEu1ageAbFKAplVQ05x4Wesgk DwVErU4EfOsKlbSU7yDDhUzbqbvRxEtYCJxnoeZhZr4NIvb8/Pe2RGF7KnQlimnVuN vUeklb87W3+Mq3Gt5fr2pRkHeUcmK65x8RhCR5/zsfQBxIPxH59QZGP4AHBjpje6wU 8HGDS0jnYgGdSXVU214nSGL+yJutRSXhhulLBIqxIfNvCGOebXIxgEHW1xwdax0IqZ C98rtbvQSOfQA== Received: by mail-lj1-f200.google.com with SMTP id o8-20020a2e9448000000b00246133c54deso4498844ljh.10 for ; Sun, 27 Feb 2022 05:52: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=lHEHPtP6JAM6zCrRNeDTlRy/WZxSvWGZvNHgREr2xAI=; b=6yIp5gdltkX0busuqyO+zCDrjZsHdszIYA1E9l1uH9DnXYHE2SxHg2H+iQsUa5IjKx XiP3qFIJg7DuFIT5t6I709JlMDF6boAr/csZL72WU76OxtxPCiEmx6JluZ/41icWfIno ec3OkD2CnWWEitA302DH3V3wps70ZrBhH/0/RM1LxskPUIEkECZkRnxIx5CV2eGZyXKr QbW1Je/0BinWEHBmEUB6G2tRFyGt3eh/ajEsPwzT2PX+9aJ1nWYJcpZeu6J9K/QV1pm+ YbVrD7COQPRu27WQWV8Ans01wt2r5psIDcG90Vh13Gy9gL83rAqJlMZikUmIykSJsOjc 3czg== X-Gm-Message-State: AOAM531OTYbta2Kl/rjSKEIRx8ben+Qu/hA5YcgpoN1MsGu566w90fmz 19bpr8mCZBWFIb9/LU2410d9lAZ9RVOJC2r/ll6wafSBuE0h10WNJ4XCD40tiRxOWLlz9FfP4EE sn5dah1QcfjVIh2iI0niog0gAhayVbUMwP58CpYMxzhg= X-Received: by 2002:a17:906:d10c:b0:6cd:4aa2:cd62 with SMTP id b12-20020a170906d10c00b006cd4aa2cd62mr12751229ejz.229.1645969956026; 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-arm-msm@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: 12761717 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 E9966C4167B for ; Sun, 27 Feb 2022 13:53:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231266AbiB0Nxn (ORCPT ); Sun, 27 Feb 2022 08:53:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231316AbiB0Nxg (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 0F8CF13F75 for ; Sun, 27 Feb 2022 05:52:54 -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 4DF2240303 for ; Sun, 27 Feb 2022 13:52:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645969971; bh=pRyoy0wYqVh1vMWkfgiwvfL+uC0PF+MUz+uOlTyWlM0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=S/WVfEuncOULSzfdfmuwsoVoS4r8vAvDttCNWqP1wmxKmVTJUNClkPsErnGdvbACB AUFBBtoUCh4QV7kl4EHuW7uzB+1qRJ3UGkPrrZBk6QJCPFbc1CY7SnoPaoY4Ge/bbN iNaSNIjy0k3mumJy6kKgkzHVGRBjhzGZ7TAyEmP5yzkBIuciKWgh/6xH6AMUmPgCsl yAIbNU4+AwE9DkcC529plcD+MFnrRr1Pb4xGTTJZ/HlR5FyvWmUNggGwHkNmnmU9Jp GVxGW96uanFOUHp2k0H9QOQmQYcr+dKIt8Moz5XXhAN3ywAASPbo9GmoQYuMCB5pg/ zY+kOLBYG86EA== Received: by mail-ed1-f69.google.com with SMTP id d11-20020a50c88b000000b00410ba7a14acso4249359edh.6 for ; Sun, 27 Feb 2022 05:52:51 -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=k8HPjxPYb1F62CLPF0tjzsUt7D2/meNNTxuQ08lVf++OyE/k06N3EzbvBaMYgDiE2j u4+YTg/QjgpSq5ITHNqzYByPPN5eq9gtRFM2KswVpsN8gBAKrH84pydlB2NqKRgqQxeH rN/2Y6j4dbxB7AL/2e+HMnqmprMlZYh5vVdGip/ilzwEZcYKkoJaFhQML6g7M8tmJTDp VuuuClzFpMRJJPJeH3ybDZpSgaVSuYl7nZY4o8l0VlmVuXSsdPjzu0QxMi9g7qD1puaI i0SM3POAmnxuI1t4fjyNTwV3TADlXukpabkJ1QNrUsPNY3NydPCobYCFtnVatX/tFkzH 9D7w== X-Gm-Message-State: AOAM532v37OQOD2WSfP4SUHpHantWlWjZJhwpo0WqbbL7HaIlzdQiTIT iZ8QzUUm/U9lH9QH4GF9bwaTNzw5Vp//Xmu6lT6tbZT3jREmqVajR9USJ4oMfl1UrvTBgk+xrPn kVjRzEq/0aURIFwmfezgYv9kmQANZ5W9BTIfy/pEs9ZQ= X-Received: by 2002:a05:6402:1a55:b0:410:a4b4:2a9d with SMTP id bf21-20020a0564021a5500b00410a4b42a9dmr15356214edb.45.1645969957663; 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-arm-msm@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: 12761718 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 27957C433F5 for ; Sun, 27 Feb 2022 13:53:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231366AbiB0Nxu (ORCPT ); Sun, 27 Feb 2022 08:53:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231320AbiB0Nxg (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 1F135E086 for ; Sun, 27 Feb 2022 05:52:54 -0800 (PST) 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-0.canonical.com (Postfix) with ESMTPS id 1FDCF40A60 for ; Sun, 27 Feb 2022 13:52:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645969972; bh=ovOgd1VJlKyRzMY+TlP34IMSMGHGw8uakjQlL885+iI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=oPt1I58u5CNT5i9KUMCuCZB69WlrMmJh2qshbDDdCAXIIw4SwfZQnzex6K4bSMCIs F1wQ1YXY4zN8JehDMTvWFsdwCmhfwgcVmXBc0JKFEQvk8wDhmQ1QVkSc8nsU17Oewb 9TicHs3hZaHa6KnaBKOpSiRfboHSldQEEBiLI3AOfOWDHu3xRjQeAZFAeVnh9chzqQ jBixMRxAjw+fdOMpVeU3QFU8merFF+mO9WmC6FP9gUhdBmLu68BO3HQDRMqu4GxeWr 51m8wQA1PYAgetRF2NogfJ5PIBjXpgIDXG79OzpSqvtvmQnXoDetmGn/piErJQs5VI SjJj6IUcHmdzQ== Received: by mail-lj1-f197.google.com with SMTP id j17-20020a2e8011000000b002463682ffd5so4498785ljg.6 for ; Sun, 27 Feb 2022 05:52: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=ovOgd1VJlKyRzMY+TlP34IMSMGHGw8uakjQlL885+iI=; b=etB2aPqmk8dwdlxuE8i8psq+3DN6gk7B1P+QM5jYbvQTGcDuVcV6bbCc0c5kncQE/Z 59xMttkn32uVGiZc6IQQwXceUI/q+vl5BrxCJ6rx8/o+Pe0cpBZm6n4MzRAe0HWAIBEB bRCBEQVkIzBnnz8g2EqJplHZB4+055bIxeieM03CBoxDjVjMc30uQV8VV5jiE7Rg+rfr SmVhb/h0iPvWu87KwwF53RqJD9I0wZ4m12VZRskCmjVVzM6wznuBXklDa7uzal7IWP8Q maYs7EvKaRCizqTnL8BfeNyMI6yQ+h34LV96j0/yZkhMBY7PFSRS/ZcEwSkgc0Zf/PLM kTKg== X-Gm-Message-State: AOAM533Et7YTQTgrPeY5MFxpnxEZaBmZ6JXXbIP6UaRk/FK44TXamWwc 3h4ja0ay6XnCad/bbOSvHi2D0DnH5KR/Y86tE+nsWzd5YjBjbU6trSpbdhFvTKcVuAH301NlhKd kFSoPhYD6BK1Zr+4+TLpWuVCWr2h2Kuu+pn0pGPw0nlQ= X-Received: by 2002:a17:906:82cf:b0:6d0:3d6:8f27 with SMTP id a15-20020a17090682cf00b006d003d68f27mr11873404ejy.236.1645969959561; 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-arm-msm@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: 12761716 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 6EF78C433F5 for ; Sun, 27 Feb 2022 13:53:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231281AbiB0Nxk (ORCPT ); Sun, 27 Feb 2022 08:53:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231327AbiB0Nxg (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 6257C13F9A for ; Sun, 27 Feb 2022 05:52:55 -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 4B8A4407C7 for ; Sun, 27 Feb 2022 13:52:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645969972; bh=kn+qF0tdCo1etTHWEFOqoxtrhJ+rC4czu2ZZy5+SihI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=G1gFAD+Oz7ocv77z52z5RGqikzOFX9l0KejqgG1Fiin+yu1PWTokXtQDlNfHVbC8E mLvct/gyI5X/vN4Bk9ZJP76bk/dhqwdlYNqXZWSRvyAc8NGPqxQfr/DsdSDJ0Q+ouN I4nr2FI88mUntTqpe8XBPCzA4BUazUMjCPXJDLNVYh6yFIOSKLBz6Wp8eCYXHIsmVt NLCFj/N7kmk6rjJuqty376MS6JKnxZMg+gYAm7qAmNOS2WKSzRhW5PHiz2D2FXqzmB lv7HUl9jC5s96onhRHeSHj99UxgkcNSy1fz32qqr2Frk2LpCby7Tl2bB5dAc/CLLLB Nyl/eaHgebeUA== Received: by mail-ed1-f72.google.com with SMTP id m12-20020a056402510c00b00413298c3c42so4243954edd.15 for ; Sun, 27 Feb 2022 05:52: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=kn+qF0tdCo1etTHWEFOqoxtrhJ+rC4czu2ZZy5+SihI=; b=SMQxB9EFgIp0Sfe1ntta5nw3TjyCSD446h7U6J7UgIvqz2N3/7jTj5XrUmxBRX1zg4 uVephTQoI5LKv6qOaNcWvzF7YPB3/xZ0kzsRnQsemH+0uORu0lZytE97XFH7O56MVJ7k a/dhZNV0jKbRR0+U83QUsFyOoXC0JvqoePWowyhKqpC1vSD3uWPkRE/tfDxlfAbeIuqq zfxh5JkAruVWvvAYQ+1mjaRKXLfVA0S11++e83LWrm1sAo04CjibG5LjzqsWUj0YL6Ke WnOQAnCqJmY34bTzSWHCyQb/9FyFFm0oI+byJRRLNHTZcux/SEqdbYhWPXwUkpM/WkPr 62aw== X-Gm-Message-State: AOAM5308QVEpvc0aMhcKTl5GhWs5mnmL3M6ydFqoqYWDSX/P5tmPkWD6 hIgAgxOE+w+Hz4LyEztLPsC1mrWTXJdC4Bu0sFDwtdUcdbUgyHGEsR+4RAmptGIZNwXZwBYOFcT fBPn35zVIjaTe9jIh6ADFkzj/2XR2pveY8qnKuKPggqg= X-Received: by 2002:aa7:c4da:0:b0:410:bb1d:8232 with SMTP id p26-20020aa7c4da000000b00410bb1d8232mr15075953edr.333.1645969961203; 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-arm-msm@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: 12761719 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 4C55AC433F5 for ; Sun, 27 Feb 2022 13:53:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229768AbiB0NyR (ORCPT ); Sun, 27 Feb 2022 08:54:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229876AbiB0NyQ (ORCPT ); Sun, 27 Feb 2022 08:54:16 -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 706CF13F87 for ; Sun, 27 Feb 2022 05:53:37 -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 06FBE3F1C9 for ; Sun, 27 Feb 2022 13:53:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645970016; bh=qpFiz05rVbRuRAHN9hg8SmLpkD4Xh7SLbxYijfSgBwA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rmhl8qCa+qnn5onf23jA3QCk+bIQPzArdPvkobAwCfvO3QNGdsjkm8CrcW5mUk9e2 RUU5Li3KhDre5xcJNeHBx7FeuyhByRQ5Vxv/Hbitfx+RnOsJCUCM8DtTGAYJZdx4Bd eCnTzVIa2zgEY1FKg+Tvdar1R0e6JnvMLzg9Xqm3eCWR5wDj3ZtZEijYJt/pr4sq/3 bsNVWxbuNTqTfmREDXzTA7IzYJDLql5zdY4S6JNdE2eHoHmomFBWTBN4t7lxwXBS/e xpsodnMv414cQNtq0qGYuVF6nCeWq44xB/AHIFIPfsVVl+I7mQ5NY2v1b4s4gMv/X6 7H7F3yqni22Jg== Received: by mail-ed1-f69.google.com with SMTP id o5-20020a50c905000000b00410effbf65dso4235561edh.17 for ; Sun, 27 Feb 2022 05:53:36 -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=oMOEKf9wPMlcV5OyECyRkEkmRw/pltD3YX58KwNzvbF0SeBdUFdr02AjaYz6aSv4DI /uPA4juinYaP3o4e1Crkr++aa6HjZ7wbe2+5EMhcOIjeBOMtrnVbPzUDteORf6l2DcUa cOop3NPditWdKnsgALVn5YxY+xR46SEhQiAniglrGfVJmspJo9zcJ1TY6tTFEkINqTLd b5uzmbTMyhVAKUF9oiViDJ/VlJ6vdzeyDcrGYFrRSZ3VqZbeJEFDTi06FFx1cTjPu57a /As3gyfvKgbJg0GyrlB7mLK65IJo4qCPm/08QV+dWjYV+Ug0PxJZ0VJnoOjL8u9cn6l9 6zCA== X-Gm-Message-State: AOAM533W/zfM6Pd9QddbovumETTAo3sWJPGYiCwfkwb4CbTltgYQ1DqV BMp3o3foZ1PNhRRuYXIn/4SOgMGvdQQi4pllmvSF+drm3z0qqSwCSSJPqTPas1hXKW9Mm6bnLfh 5TsT20pFqoc82+NeVNhFLjAl64nJOA+8t3fbmgSfQDKY= X-Received: by 2002:aa7:d98a:0:b0:410:b844:7889 with SMTP id u10-20020aa7d98a000000b00410b8447889mr15100885eds.109.1645970015738; 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-arm-msm@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: 12761722 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 D4D9CC41535 for ; Sun, 27 Feb 2022 13:53:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231372AbiB0Nyc (ORCPT ); Sun, 27 Feb 2022 08:54:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231354AbiB0Ny2 (ORCPT ); Sun, 27 Feb 2022 08:54:28 -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 E4CDE193EC for ; Sun, 27 Feb 2022 05:53:51 -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-0.canonical.com (Postfix) with ESMTPS id 156F3407C7 for ; Sun, 27 Feb 2022 13:53:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645970029; bh=npGNvoQmcQXzOf9MUvG7bOfkjnwx60Xk35PbEgCfPxw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=CL4WkDLCi60/NGuds/AFWF3XPOTztfy5Z01ljoqhHoPyMjsJAs0835fNRoSZC1Y9C qBIJiPqebtToClkcpohGOj6qLFs7oc7nWVLM+07JQqUvOA18r9eD0nhacbn13N9oVv VVmGQwqsxFUW9vQLKJBPcMFEc2KFJhPxa0Lrl7Oc2fqYT3oiknWVpEFOlpq2sSt0Ln 1lkPSORG83XF+lcYIJTdhOLz/eKlieIpUPeh0XXqjG3yHZKdMVJEbB2NjHKF8Xkhsp XnMTzKxE+wE4wVqmoNghjfEDGHmpLkYJj6jlSNOCmr5wXlJ/ZOOEMn1Mnyd97LWevR qJy6gFigPYGyQ== Received: by mail-ed1-f71.google.com with SMTP id cm27-20020a0564020c9b00b004137effc24bso2416883edb.10 for ; Sun, 27 Feb 2022 05:53: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=npGNvoQmcQXzOf9MUvG7bOfkjnwx60Xk35PbEgCfPxw=; b=kEmlWrBUExgNSE+0pmWehyj73K/v7Xj7rS6AnFS/5IuCNaHIfK0HWiW2OnrRH5oGG8 4bu9xf0HY+ld6/4/sJkocyhPZTHvch8/PV8qELbWLBu3KLA8H/7moXShAG5yqq5euuqd UZgKipwlz6owUhCKYCppI8AIpn9IyDQK7YZ+aVJqpaky3A9dzCJP5V/A/WovNDyI73rT tNNGnQOzX+GXBFWO1yob9bWclTwRuCQDYWcZWfHxLwqhJ+AXe8ehHpj5mrTJaVTX2GVD 71I5pNtcRx0lwjFgLQNvnZLG79Qw0Q5ff5vYZKiT1Xj9mPq6wt2bpxbjv6uF+x8xhiXT JKdQ== X-Gm-Message-State: AOAM532cFCtxBa17+ZVF3BNaVJ+wxZupKoqMEHgmbaSgxC8cqhA5WPyQ DuJ0CclfAi1a70XO1SqKvJRxK9JP1GeELAFHm1vABjDc5d5jGyXlICLApjHUrItFWciKOxSUqF6 8zyD+gEfeptzPyOnGN28xaLANg4ngP+4Fqr7W8PjFtDc= X-Received: by 2002:aa7:d49a:0:b0:410:875c:e21b with SMTP id b26-20020aa7d49a000000b00410875ce21bmr15261505edr.357.1645970017416; 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-arm-msm@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: 12761723 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 5A5E5C433FE for ; Sun, 27 Feb 2022 13:54:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231423AbiB0Nyj (ORCPT ); Sun, 27 Feb 2022 08:54:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231378AbiB0Nyb (ORCPT ); Sun, 27 Feb 2022 08:54:31 -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 40A081BE8C for ; Sun, 27 Feb 2022 05:53:53 -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-0.canonical.com (Postfix) with ESMTPS id 9196940017 for ; Sun, 27 Feb 2022 13:53:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645970031; bh=x+DOMuEjhXppqlmSDNC0RKdzUzslcBqDhsGS9OsoQS4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=fqtz3nQVi5TjYwJxw0nX5FCG8CIsVmwudBKZjnrG6qv4VqMjYplEwyu1maQjtgQ3n 67CUny07O8wu7hmOMlwti7I1WieNvenhJytR9Eukoh9grNqpIu+Tod4NrL5d/Bmd2S wfXCTvxdcbq+RKgCGnbv44rAVPrRtXdz38zMz61DfBvLra+8aG3zepPL1A6su+Dcz4 +i8zRhowqxldmJhyzqHwO+gtyxPpQ3HbXFyMXS4xabAXet8sXK/eXV9gcYphq80bwN 2S6deJfQuM6H3Unt6lBLDQO8+mxgkbq8Vf0julCPRtuQNhmVnJffh2+l9a3uxBTCxX uzj4+QgkJRlNg== Received: by mail-lj1-f199.google.com with SMTP id 6-20020a2eb946000000b002463d2915d2so4495046ljs.9 for ; Sun, 27 Feb 2022 05:53:51 -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=cI5nFbBgQ36KJPeaCXHFGbfzjiuthy3RWrAx/EcuXZxr0OsDu2d1vAQTpj2DS4iuBR dQWa6UO5rXZ613u6030hmhIgDqhoNUcek+zJWH3Q8CwC3jwudlQY6q27v5N/NzHwk/Kp obOGAlF8ba95HQPopBGZy/N3PuY+MXynIjTtkiUgi2pp+WC0BF78d+6KuoPIBxIaZp+5 qxz9zZLq8lpDwh86XhZeEuKF1HdsK00qZTgGmrHgA6iV65PNmkEV+ckoMBEBCExayFu3 X9GSB36r/e2j2JoE528FrmElH1R6I1W7Pb+VtJTdnKozYQcYFoBuf3Ab6N0foxq3+BBo zovQ== X-Gm-Message-State: AOAM533YnJiDVQZTlbtorWkNMdEgRCk5+Y36WlShzQ0cVVNifJicsBSz gQqA+tbpTX0YLU8P/DaQBiwwI/MGJ8KZpCXG52j6mNmQzsPl42Qg7CSUTtGgWPDDFWU+pFXo3nI bB77KULnE+mId4Ob2qYRkvBq7oc4iOnXOXfJWQV4oum4= X-Received: by 2002:a17:906:354f:b0:6b4:1449:2d03 with SMTP id s15-20020a170906354f00b006b414492d03mr13078927eja.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-arm-msm@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: 12761720 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 52DFAC433F5 for ; Sun, 27 Feb 2022 13:53:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231326AbiB0NyX (ORCPT ); Sun, 27 Feb 2022 08:54:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230470AbiB0NyT (ORCPT ); Sun, 27 Feb 2022 08:54:19 -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 58B5C13DE5 for ; Sun, 27 Feb 2022 05:53: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 381273F02B 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=Ittcal6Pd+WYY4FgdYnMj0oR0y7noG6anoPNpq8mwII=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MfA22CvYBUUIvpI2+eRjFniMalFMd4ttSDNNE2THW8LMvYQE2vU9yoZoCLyjpvUGY eMi+gnCiYrdx+ASWsEmSeaQ0sRRGQhdPC0fY7Q3vnqit/HBXD5dTH2s7usPeZs9tOi XH6DrS/oXKXpmQOgrG42dlxpFlLNAjqmu43zZqrRsK2BqJiGvU0OzTHH+kOEhYgF6k SI1zwH1csmWBNL3yGEGIGhiU+SQu6agY+E02WoQ5VWDctAxAkMPLrzVUrqRzXNpm9V AtmVCISUOXGHmJajn9Nfd+Sawa5MsYNXA6oHYM/yM69yPhlJkNtLvgs+gN20ze7uX9 jAucYoCN0v3aQ== Received: by mail-ed1-f72.google.com with SMTP id j10-20020a05640211ca00b004090fd8a936so4230092edw.23 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=Ittcal6Pd+WYY4FgdYnMj0oR0y7noG6anoPNpq8mwII=; b=g2FYQVhg2lKFrhN6ajZlo07W4Mn+zeyEy60qq9lC8b05uGa4Qft+EApjFxRQ5UjKsM Smts9+l9YioHSiVHxwi0gdZl2NEhz1wFptcsK4PPvq+/cfU2KYS4LlmnO0in73jtlh0l UkJoh74ghpxYOoB2Ru3Pl/Cphf3OLZMwhIClDEyNF+EEBRJxoIUgMameesjsgcqyZKEc +yVD9vcsDC9vmp4q5o03WH+J9Zn6LCLsPZI/mKHyjwvQ7k+7toJEjx1DLShZB0nKTdqu id02TjO7m2Y36wk3FWfHgZDIsbs6fULvkpsBkT4g8cHJzKRwfbccONVQ/6CB8ouyRyUY 0N3g== X-Gm-Message-State: AOAM531mYyEj9wckC96iXFYA/edkDLb0S9KdYLj9jiIpnlWwpdUvpdqI Vfie5/RWm5mxo1xPV4JH99pdu5dXHvJI8jXyZ1LtTQbawfuyD+o2DzH/rtt0bOwy1E9MPwQle8B JIB6WuCuRJ82cPZOajIIW69YfSIM0G38vdYTaOo6vPv0= X-Received: by 2002:a05:6402:42c6:b0:412:8cbc:8f3d with SMTP id i6-20020a05640242c600b004128cbc8f3dmr15364955edc.310.1645970020949; 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-arm-msm@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: 12761721 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 DBB24C43219 for ; Sun, 27 Feb 2022 13:53:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230400AbiB0NyZ (ORCPT ); Sun, 27 Feb 2022 08:54:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231287AbiB0NyW (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 04FA41403E for ; Sun, 27 Feb 2022 05:53:45 -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 5AB294005E 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-f72.google.com with SMTP id b13-20020a056402278d00b0041311e02a9bso4197520ede.13 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=ClDsZg4Odoy2fxCH6Sw8gGDqI5g2tOFiG3gtPDg72BXYsv1D1luzixS6pVp9IxQ7Nz AhIXiNzJVEB32pjlsp+mI4sFfhavxAzSIROC0EsZHGibq36+HI6389pFY99y15HhE7dg 5VZyIm506D7p2Jm94UN7Mn4dMYxX5dI3Z7BnSaXrIKHBMPQwIoR6spgYzOAb3CjIs9ao ZRht0mxtZLjs2QDdudASYGZAvME+EGazUqdaNow4+MkciBSUER21yVVDkKjoKN3l88la JTRDQBtrpWt/2WIUsudIyNnmap6cPPAHpg2uV8P8Bs2VBNvRFxNkYAFeTbb0jNhIF8lN vnBA== X-Gm-Message-State: AOAM532RuU1B9uKVk+NZnxM5kuQw5qdDLuZKDfmrlP2GYmNyfekqnoBg N4g9lZx6NS8nyjQ9Md2bWOnQNjl4v/Qm0+Wq6dDA9V7Bid0TY13XCzQP6nE5pcYdxyx1KbNHewI Vlg6xk69FlIv4aVainu7Y2J3qKGxdnnPr/X0pIhNyOQY= X-Received: by 2002:a17:906:d8dc:b0:6cf:d1d1:db25 with SMTP id re28-20020a170906d8dc00b006cfd1d1db25mr12142699ejb.285.1645970022948; 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-arm-msm@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;