From patchwork Wed Feb 23 19:13:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 12757396 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 97675C4167B for ; Wed, 23 Feb 2022 19:14:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244249AbiBWTOs (ORCPT ); Wed, 23 Feb 2022 14:14:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244218AbiBWTOr (ORCPT ); Wed, 23 Feb 2022 14:14:47 -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 E16A641302 for ; Wed, 23 Feb 2022 11:14:06 -0800 (PST) Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.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 14E9E40296 for ; Wed, 23 Feb 2022 19:13:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645643633; bh=jDkZtIbGu7Rx+CZZvT8FrNfVIDpOYhUi3Zl4KFBr3UY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nTp19xxVAbTxz3Wu3Tj/RYLu/Lc1Zjp/vUm8sJVZV1zvdvZjJGD0w18vS9w3JJ6AN /83gMiqb+2vt8y0qnUVk5YIwmMkJTCcem2SKgVXFhKcNiu4GOqEOB+k4WQXn/LQSzV 66FLqutgj6eDdMLUSr8xiYsN344hly67dIOh5ZYx9TcLQLQegYCwRHXmiLwWCRFFL3 anbYXhZM9iqf3Ie4/bsAuHeTx1DuHSe9f5CtY1gjhBs5CN5ZQYvgRj+fJfRZt4T6PB /QvOQsNaUPhua4wTgHc53pMc+ttqOeOt7CWdA3UjJA5cMa0tnR0RHtMH3FVGFQqPah rAOX+afS7vx3g== Received: by mail-ej1-f70.google.com with SMTP id qa30-20020a170907869e00b006cee5e080easo7439115ejc.3 for ; Wed, 23 Feb 2022 11:13:53 -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=jDkZtIbGu7Rx+CZZvT8FrNfVIDpOYhUi3Zl4KFBr3UY=; b=prh530FBXJ07rmqZAosWHJ7OJjRlPuqqPFHRQ5ZtsGoYEB9z7MHSz2GoyVFitrlxo2 iacEO7ubH3uzcO3NWbnsoRCSbbMqYm+4+t3HE84hLXRW8EHGm/UMjjM6UgeCFsDcvXVf a3xvTf3/UhE4sLkzE/dx5UWoSiTSZa1O5z85r8aYnVohCjUYSGs9OivDsiaGWme5AS9A cJ0vhFqEOyowfTgFT3oq66tO1cCQ21SPnGAk068cx5+TomEtNmUvj0uMroYuESQn7C/X InBJAvl7n3Tox2CGNMdXV6NN1pVzekQ/9WlLIH2rgEUqlGD8ahiXfP8ooEKW1eKM8CAP QGLA== X-Gm-Message-State: AOAM530Kx+pwJtZZP2Mii3B0+dvea9LuHi8jPrXx+gMdbSu2nXdvalGJ CGuS0ZLRilQniPBVFT/8nWmjDayGHlmO+8qTmriLrgWiDT2GNb5dnQHZBLsRl7aObpooqVjKypN r6U01twCoUBJXWLGpfv7EPfoQ+0/BfyhDvYscsA== X-Received: by 2002:a17:906:16cc:b0:6ce:e607:ff02 with SMTP id t12-20020a17090616cc00b006cee607ff02mr872215ejd.418.1645643630085; Wed, 23 Feb 2022 11:13:50 -0800 (PST) X-Google-Smtp-Source: ABdhPJwxRdig8NaceeNOO2F1vxV5JTwYIw54VeRpY5+G4e03MaYaAg/BDtvoqP0gdGTwXBo6IyszVA== X-Received: by 2002:a17:906:16cc:b0:6ce:e607:ff02 with SMTP id t12-20020a17090616cc00b006cee607ff02mr872176ejd.418.1645643629849; Wed, 23 Feb 2022 11:13:49 -0800 (PST) Received: from localhost.localdomain (xdsl-188-155-181-108.adslplus.ch. [188.155.181.108]) by smtp.gmail.com with ESMTPSA id q5sm212611ejc.115.2022.02.23.11.13.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Feb 2022 11:13:48 -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 v2 01/11] driver: platform: add and use helper for safer setting of driver_override Date: Wed, 23 Feb 2022 20:13:00 +0100 Message-Id: <20220223191310.347669-2-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220223191310.347669-1-krzysztof.kozlowski@canonical.com> References: <20220223191310.347669-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-clk@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. Signed-off-by: Krzysztof Kozlowski --- drivers/base/driver.c | 44 +++++++++++++++++++++++++++++++++ drivers/base/platform.c | 24 +++--------------- include/linux/device/driver.h | 1 + include/linux/platform_device.h | 6 ++++- 4 files changed, 54 insertions(+), 21 deletions(-) diff --git a/drivers/base/driver.c b/drivers/base/driver.c index 8c0d33e182fd..79efe51bb4c0 100644 --- a/drivers/base/driver.c +++ b/drivers/base/driver.c @@ -30,6 +30,50 @@ static struct device *next_device(struct klist_iter *i) return dev; } +/* + * set_driver_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: NULL terminated string, new driver name to force a match, pass empty + * string to clear it + * + * Helper to setr 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, char **override, const char *s) +{ + char *new, *old, *cp; + + if (!dev || !override || !s) + return -EINVAL; + + new = kstrndup(s, strlen(s), GFP_KERNEL); + if (!new) + return -ENOMEM; + + cp = strchr(new, '\n'); + if (cp) + *cp = '\0'; + + device_lock(dev); + old = *override; + if (strlen(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..d8853b32ea10 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -1275,31 +1275,15 @@ 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; + 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 = pdev->driver_override; - if (strlen(driver_override)) { - pdev->driver_override = driver_override; - } else { - kfree(driver_override); - pdev->driver_override = NULL; - } - device_unlock(dev); - - kfree(old); + ret = driver_set_override(dev, &pdev->driver_override, buf); + if (ret) + return ret; return count; } diff --git a/include/linux/device/driver.h b/include/linux/device/driver.h index 15e7c5e15d62..81c0d9f65a40 100644 --- a/include/linux/device/driver.h +++ b/include/linux/device/driver.h @@ -151,6 +151,7 @@ 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, char **override, const char *s); 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..37ac14459499 100644 --- a/include/linux/platform_device.h +++ b/include/linux/platform_device.h @@ -31,7 +31,11 @@ struct platform_device { struct resource *resource; const struct platform_device_id *id_entry; - char *driver_override; /* Driver name to force a match */ + /* + * Driver name to force a match, use + * driver_set_override() to set or clear it. + */ + char *driver_override; /* MFD cell pointer */ struct mfd_cell *mfd_cell; From patchwork Wed Feb 23 19:13:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 12757397 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 9E549C3526E for ; Wed, 23 Feb 2022 19:14:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244274AbiBWTOt (ORCPT ); Wed, 23 Feb 2022 14:14:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244231AbiBWTOr (ORCPT ); Wed, 23 Feb 2022 14:14:47 -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 E75F84161F for ; Wed, 23 Feb 2022 11:14:08 -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 BD8AF40306 for ; Wed, 23 Feb 2022 19:13:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645643633; bh=HpbyTrdXrFaP+pceEvy/NrkKlPBl1rW1ivTy++yPdQg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=lF+u9h7M8SaGGj+BVyjX0jOZumxyccm+OdEcAbmYNGxAwerixclXgNWSgohMe+KOS Z47RNhg+hCoxblhOMU9LreR/HJ+Zn5M7ODjqWJeBuBxeaGwb4nBzg30oV6qCkl050l kjQeCvYrlUhxnEXYiywittN0rtgZ2lBKDITs7P/fE/FuRGqlpNonAbQdG7NCymUF3q aA268kbG940a/TIehbDStEeaE1qBXigBvVvH/iGe2FsRlPNoBYPtW+Ixw3Bc6xHQAm +b8mNNvI7bm3D0CsmZQw1uiYxl4beUlCWgnRlhpyv3S/lQKmPqpvnLZXgnQKU4DRkv yd+GYNWHgLfWQ== Received: by mail-ed1-f72.google.com with SMTP id eq13-20020a056402298d00b00412cfa4bb0eso9246990edb.7 for ; Wed, 23 Feb 2022 11:13:53 -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=HpbyTrdXrFaP+pceEvy/NrkKlPBl1rW1ivTy++yPdQg=; b=wGlex9p8WTOlWh4s3JBRixskazz8WgTa6cxNV0QTm0pWXSh2RCFdYw/rpEZfKr+T/H DCd5AZilv0qC8tT5qu6uJ07h/dNrhHYqWRcurcmqJ+C5UWScQdPYYXBg4BB7X5B1H1QT JRIgsdrsy8HlDGz5xZjq+2XM2PjEzDTGqVNj4tgIisQM47aiOcjrITDVHEIAIf7wW2vA 7ooAXz2jgPIVLZuNleeYqQ13l/KJoXKYIYELu3OExOZ81YH/23cXnJU9ctTkS3Ds6ZHF PFu3lWid1GzaPWn3BJ2zbChbz2VVN0jv5SwmQcCP0B3H4XLqZkZ2znIguf83dnCWS0Gi bs8g== X-Gm-Message-State: AOAM532IawxEX18ZS+BXQdGSjaxzYEPiCB8hvV/sMYUq/MSXVQANnZDc BYDSxzEvj4VTHwry8H8SNqMx12qF+uCGnIiE6Qma6ndEpsdhvqbqnZCx0P/H3JTIV5FOaTeWNc9 5XTvrWhvSzcVJMaS1hvXaKegl/buM/wXTzZFg7w== X-Received: by 2002:a05:6402:d05:b0:412:e171:28d9 with SMTP id eb5-20020a0564020d0500b00412e17128d9mr848358edb.169.1645643633262; Wed, 23 Feb 2022 11:13:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJwYG5EE1VK62qsOOiEHtkeJRCih/epa6U/E9Szqr9uJDRTwmiXA+urJE3qxE0O0qjjabVNPNQ== X-Received: by 2002:a05:6402:d05:b0:412:e171:28d9 with SMTP id eb5-20020a0564020d0500b00412e17128d9mr848325edb.169.1645643633058; Wed, 23 Feb 2022 11:13:53 -0800 (PST) Received: from localhost.localdomain (xdsl-188-155-181-108.adslplus.ch. [188.155.181.108]) by smtp.gmail.com with ESMTPSA id q5sm212611ejc.115.2022.02.23.11.13.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Feb 2022 11:13:51 -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 v2 02/11] amba: use helper for safer setting of driver_override Date: Wed, 23 Feb 2022 20:13:01 +0100 Message-Id: <20220223191310.347669-3-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220223191310.347669-1-krzysztof.kozlowski@canonical.com> References: <20220223191310.347669-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org Use a helper for seting driver_override to reduce amount of duplicated code. Signed-off-by: Krzysztof Kozlowski --- drivers/amba/bus.c | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c index e1a5eca3ae3c..12410c05ec70 100644 --- a/drivers/amba/bus.c +++ b/drivers/amba/bus.c @@ -94,31 +94,15 @@ 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; + 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 = dev->driver_override; - if (strlen(driver_override)) { - dev->driver_override = driver_override; - } else { - kfree(driver_override); - dev->driver_override = NULL; - } - device_unlock(_dev); - - kfree(old); + ret = driver_set_override(_dev, &dev->driver_override, buf); + if (ret) + return ret; return count; } From patchwork Wed Feb 23 19:13:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 12757399 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 EC7A2C4167B for ; Wed, 23 Feb 2022 19:14:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244241AbiBWTOz (ORCPT ); Wed, 23 Feb 2022 14:14:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244240AbiBWTOx (ORCPT ); Wed, 23 Feb 2022 14:14:53 -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 738C140E6A for ; Wed, 23 Feb 2022 11:14:25 -0800 (PST) Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.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 417343FC9F for ; Wed, 23 Feb 2022 19:14:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645643660; bh=fyZde4QL+5WSjtUcZmZyQ9LOCmYULjkOm0dq/nBIuzo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qBQokoKPizZLZ2UnvkN5VQded3OZUDYY/lI3AaUtyPCslWX9C8iYDV79FjJVKWgsR S6DYndF+9pGS3EYK+tASbPwfg0i6rPObQ0OGnIUxWoqIphXizAE5TDRt00hwmM8NLH VHo0WpxTX0P3aIHQQUhLqDYj7BPdKiQ9zHYhymZR3lq9HC9HmnQsezrvHNBImknJ2x zobPILGpeX5aE/Up+rM51f2ebl7NLC9uUuxOgHVyJdCoY6/ByyuFzqKg27kicoh7WY FLg5r2wwE/jCCkn8vhSzl42QHXKp9fTuQOhm7eE850mUKEAdODehcNpKh7HgpxCoNf QH/ky5jmbWxZQ== Received: by mail-ej1-f70.google.com with SMTP id m4-20020a170906160400b006be3f85906eso7480070ejd.23 for ; Wed, 23 Feb 2022 11:14:20 -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=fyZde4QL+5WSjtUcZmZyQ9LOCmYULjkOm0dq/nBIuzo=; b=fbmimx3IScidxyZVrer+dxypoKpFcJGkWSYK1QuEmVivxgyLW4V4gHZkPBQ7rMdw2T 5qhX9tRSowh1ZjZrHibFrPbvxjjOjyvXtL96loYwINmI1QjoL5CcKwXNO/zi8wB6ljzs 0DvEZ5tDRncV2qoFHHyClPmLBClevMNRQKaoA3HaZpar4worTgDGrs8gyS9kbGBuHKSU H4fYVuUDxLBatMaVXKTNWh9yL/r05GNqkn2hFefZWfr2rELVsG96ueKxjbxOxN07pCL8 t5lBnKvrramgEqsEpjxfxl54qQIwiAo7QjBtdHFUt7N/4lIp4E6fg9pUKuJGSvRuBjHP SQZA== X-Gm-Message-State: AOAM531vYKsoj5fG+h6L0b94irYxmaOvTVAp+KQHo00/yhsv2FB6Oj6P iXrGwLgzlexOFnoy+cqcygzvUVbkldDszoW9IG1BAoYXgZ2VJRo54sCuKpGkVSNRf7RW8NdusMu gjGRphp4iONu2MwRW+9Mjq7DOAI+gSM2TxaDc9A== X-Received: by 2002:a17:906:a384:b0:6ce:c3f4:c59a with SMTP id k4-20020a170906a38400b006cec3f4c59amr870074ejz.580.1645643635869; Wed, 23 Feb 2022 11:13:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJwQC18HONgcYdOr4fLdW/4QMQU7ra3n8dm0IepMHQhTlzr1OkJDjXXGMuSAKvUFTDXd0c3row== X-Received: by 2002:a17:906:a384:b0:6ce:c3f4:c59a with SMTP id k4-20020a170906a38400b006cec3f4c59amr870048ejz.580.1645643635630; Wed, 23 Feb 2022 11:13:55 -0800 (PST) Received: from localhost.localdomain (xdsl-188-155-181-108.adslplus.ch. [188.155.181.108]) by smtp.gmail.com with ESMTPSA id q5sm212611ejc.115.2022.02.23.11.13.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Feb 2022 11:13:54 -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 v2 03/11] fsl-mc: use helper for safer setting of driver_override Date: Wed, 23 Feb 2022 20:13:02 +0100 Message-Id: <20220223191310.347669-4-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220223191310.347669-1-krzysztof.kozlowski@canonical.com> References: <20220223191310.347669-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org Use a helper for seting driver_override to reduce amount of duplicated code. Signed-off-by: Krzysztof Kozlowski --- drivers/bus/fsl-mc/fsl-mc-bus.c | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/drivers/bus/fsl-mc/fsl-mc-bus.c b/drivers/bus/fsl-mc/fsl-mc-bus.c index 8fd4a356a86e..d93f4f680f82 100644 --- a/drivers/bus/fsl-mc/fsl-mc-bus.c +++ b/drivers/bus/fsl-mc/fsl-mc-bus.c @@ -166,8 +166,7 @@ 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; @@ -175,22 +174,9 @@ static ssize_t driver_override_store(struct device *dev, 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); + if (ret) + return ret; return count; } From patchwork Wed Feb 23 19:13:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 12757400 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 F3A93C433F5 for ; Wed, 23 Feb 2022 19:14:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244285AbiBWTPD (ORCPT ); Wed, 23 Feb 2022 14:15:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244228AbiBWTO7 (ORCPT ); Wed, 23 Feb 2022 14:14:59 -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 DCD39403EE for ; Wed, 23 Feb 2022 11:14:29 -0800 (PST) Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 67EDA40314 for ; Wed, 23 Feb 2022 19:14:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645643665; bh=6kmYalWKPfFv5VRw+oGSxmK6RPimpkHdVtl6uKB49Rw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=lypfQ5EHzpPmMptBnb1UN2iDFehpADD2VaDxcZwFK3pUxK58kF5AOQV48s64IfLTr Vqhh3CRJ+x2XxCGdvUTryHx68LR1CYFIl7nFH7uLw4C5/JplFp6fPsVYqSOZy9yk1I WEDg5qj5nxzd/uUGk0dXdLCbFc8azwjZc6ZtJKqAg9h8sKbIekQyfcRMElOwwp5X78 96Bf7WiFsP0OHi+sWOgnbgqljfBGuUt3Y5ZDjOjpnis9IgvSt0Igr6Ni2Z+HksoQQ4 f+PVM6Dn2KeDR2gp8YLzRhS/gGzj9bgI3cJr0VUtTt7XSytE/5aQwDRvw6tNjFRmL8 +G1t7eZX4F5KQ== Received: by mail-wr1-f71.google.com with SMTP id c5-20020adffb05000000b001edbbefe96dso826167wrr.8 for ; Wed, 23 Feb 2022 11:14:25 -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=6kmYalWKPfFv5VRw+oGSxmK6RPimpkHdVtl6uKB49Rw=; b=QpdwrDsVeGfNxSiWjxGfqYg/dme7I47896oRpakswAsOrFfO2RRSvuEKs9NHbS36n/ PidPItBSUnKiIp5WWaAvGcvkAlWEwqSzgcvvMfPi7fh3s68Y2O5UzSLpFY21lDUCqmP8 RD4SGD4gm+m56dyfffldQxdFBmT+etN7euWwMX/lQcx1XBcFO14glR8RjDNxhZuYAhiO bxR2LNPl5NDQHBnVnvMXUxmD4ntde0qpEbBz9LnmITyDe2ho3qbQvM42+oxmOaSmZILd gKQpQ2UC7IeTIHjgQSYtbA7HNWtw7D0Hf/SN+pcILXu2KWg4aaOXxS1+yFKtwMrezCwB EDIQ== X-Gm-Message-State: AOAM530FGKkN5ttd9ynvp1Y5BGUkeaZ7XlgHwJcaP6Z/NumdtjE7oNid iaz5RSKs6Jiu75180lbUZhpsR631O5hjxzcUmCGOH7uYiaZL5rKjiLPmiM3F4Vgk4tLs+KdKQi8 Spjey4fgYhM8HOloB2hzsvZ9XNHGGjiqQgi1eQQ== X-Received: by 2002:a17:906:8517:b0:6d0:1de8:cb6e with SMTP id i23-20020a170906851700b006d01de8cb6emr879394ejx.686.1645643637575; Wed, 23 Feb 2022 11:13:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJxB+J8rGAXqipxoP9wQ6myB7nB+zWmd6qpvw2I7Sb7Voa93sYSAIKWPaoRnjyaDxxppMxF7NQ== X-Received: by 2002:a17:906:8517:b0:6d0:1de8:cb6e with SMTP id i23-20020a170906851700b006d01de8cb6emr879348ejx.686.1645643637394; Wed, 23 Feb 2022 11:13:57 -0800 (PST) Received: from localhost.localdomain (xdsl-188-155-181-108.adslplus.ch. [188.155.181.108]) by smtp.gmail.com with ESMTPSA id q5sm212611ejc.115.2022.02.23.11.13.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Feb 2022 11:13:56 -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 v2 04/11] hv: vmbus: use helper for safer setting of driver_override Date: Wed, 23 Feb 2022 20:13:03 +0100 Message-Id: <20220223191310.347669-5-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220223191310.347669-1-krzysztof.kozlowski@canonical.com> References: <20220223191310.347669-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org Use a helper for seting driver_override to reduce amount of duplicated code. Signed-off-by: Krzysztof Kozlowski --- drivers/hv/vmbus_drv.c | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c index 12a2b37e87f3..f2435cc8b680 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c @@ -575,31 +575,15 @@ 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; + 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 = 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); - - kfree(old); + ret = driver_set_override(dev, &hv_dev->driver_override, buf); + if (ret) + return ret; return count; } From patchwork Wed Feb 23 19:13: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: 12757395 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 C0FCBC433EF for ; Wed, 23 Feb 2022 19:14:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244195AbiBWTOb (ORCPT ); Wed, 23 Feb 2022 14:14:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244192AbiBWTOb (ORCPT ); Wed, 23 Feb 2022 14:14: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 3614631213 for ; Wed, 23 Feb 2022 11:14:02 -0800 (PST) Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.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 C44663FCAE for ; Wed, 23 Feb 2022 19:14:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645643640; bh=rf7a9EFQwPOyocENu81tYUT+5dnJvDmCZPPvLR/17AA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=f+ceqsv4pvZHP257w8BdgIPI5o3FDlW8a6hbBjiz1RvtSa1juNWOviEgpaas82WXY pdYGhLhD3k7/1wKJlAu7hEHaaWlL1VTMXHVZX0uW/kKjBGeTq4IUyyJbpvbI7nq78p SUf546blbwfhXIayCslnSmqk3eqDi5t/c1XfzcDjsK5JkUAQMHjTmEBNB4EmwUuPMr qhDfvhJ9nGm9fx5pypKlI8Vh7ALbwpeJrKRALaH/ppDR0iLi8RgeSimgWk/12ojpny exvVH2BNB/TpMduToqj5lGJHVg0l98NdNwDnQgUwvuKtnR+nQRUcMr0lGLZWFVAC5d wNKE3xrkwWhgQ== Received: by mail-ej1-f71.google.com with SMTP id k16-20020a17090632d000b006ae1cdb0f07so7477176ejk.16 for ; Wed, 23 Feb 2022 11:14:00 -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=rf7a9EFQwPOyocENu81tYUT+5dnJvDmCZPPvLR/17AA=; b=PUUBWcjwIKgkAR68AQS0weESAf0nwxV6TMOGTk5mZY0Dq1pTB2n+AL+UiX/SQH2Ile t0QXK0pGIcxt7KBORkRgbZochhWwcDH/8ferazBz54ReHFbqWeAAkyCSGWcOs0FA+aHh NeVwE0JZTL2LxzPjgiaGrp9Isuv/XkR5vxmhgjRjOLvrrl9I2iiWZXfKbmLXdbilXQXJ CnSzMb8uh5vccUvjJGuH3c6MATBqx+VueYEvEBQhQytyjCyHW5rz/hhNZs7wPsbcjjNN xQdvk1G5i8pWHlxliAmuYf7w+2JEysKsmjrGgPWMnC8ZbbVNlLo0+m3Qpm6yZXAQj0ko Nexw== X-Gm-Message-State: AOAM533Y4H3HopcjpWzUgt1Pwl7tlCZPL+UEU1zz9SnNJhqF2kM1Wqdu 9EAjikbg/mAk8v1g/KvCcdPJPp1CjTQcwmeK1kVTiCzLohUqJHb0f+2mCwUvmmjLv4KBwA1p0eL xsAEOVAA2Hw3Pol3tTelGoYygKWjSQBEJF5gppw== X-Received: by 2002:a17:906:e244:b0:6cd:24e3:ab8b with SMTP id gq4-20020a170906e24400b006cd24e3ab8bmr856440ejb.633.1645643640108; Wed, 23 Feb 2022 11:14:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJyXgfLS9GHyX1kCvT/o1Mu24QLFIsYnwLPgsBOYcxKH/GiFu7jQtQB6sjAsK4TU39w3xnST4g== X-Received: by 2002:a17:906:e244:b0:6cd:24e3:ab8b with SMTP id gq4-20020a170906e24400b006cd24e3ab8bmr856416ejb.633.1645643639914; Wed, 23 Feb 2022 11:13:59 -0800 (PST) Received: from localhost.localdomain (xdsl-188-155-181-108.adslplus.ch. [188.155.181.108]) by smtp.gmail.com with ESMTPSA id q5sm212611ejc.115.2022.02.23.11.13.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Feb 2022 11:13:58 -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 v2 05/11] pci: use helper for safer setting of driver_override Date: Wed, 23 Feb 2022 20:13:04 +0100 Message-Id: <20220223191310.347669-6-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220223191310.347669-1-krzysztof.kozlowski@canonical.com> References: <20220223191310.347669-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org Use a helper for seting driver_override to reduce amount of duplicated code. Signed-off-by: Krzysztof Kozlowski --- drivers/pci/pci-sysfs.c | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index 602f0fb0b007..16a163d4623e 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -567,31 +567,15 @@ 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; + 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 = pdev->driver_override; - if (strlen(driver_override)) { - pdev->driver_override = driver_override; - } else { - kfree(driver_override); - pdev->driver_override = NULL; - } - device_unlock(dev); - - kfree(old); + ret = driver_set_override(dev, &pdev->driver_override, buf); + if (ret) + return ret; return count; } From patchwork Wed Feb 23 19:13: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: 12757398 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 80D20C4332F for ; Wed, 23 Feb 2022 19:14:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244220AbiBWTOv (ORCPT ); Wed, 23 Feb 2022 14:14:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244260AbiBWTOs (ORCPT ); Wed, 23 Feb 2022 14:14:48 -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 3AE34427EC for ; Wed, 23 Feb 2022 11:14:15 -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 18560407C5 for ; Wed, 23 Feb 2022 19:14:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645643654; bh=BfVj2+YbqU03eg9FI58FYBrziSuvlZ92uC4zdqn5CTE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=FeQ1H6XC8V3WXfVyoGk/lLB5m9ReO6lba9LpzkGjwMyOlfrfxfTPxGT6h22GmRV1V cBvHex5Xt+wQoQevbJ7KR7tVx09kn4w8R2HK+hV1XwBstjAW1iqImpQJPiCJj7q7a+ TsXb2crA3d1UD4+SVhgajTfgIBvPhri11Tp40JtxfQP8/PMdQrqZDqGK9yJyUmBG/k kKcEtvNSdy4GWwXADGBTPT3T29YjHVdQp8/a1PObHsqk6vaQVdT/MzyApG3BxWIc5i Vkn8bPEUc/A9s5PBB17Kz26qx8VEjMph34+oytqhnr2FrjRMJAYnF2Xa/XxLmU99Z5 AriCuRiH9kkTw== Received: by mail-ed1-f71.google.com with SMTP id d11-20020a50c88b000000b00410ba7a14acso14057684edh.6 for ; Wed, 23 Feb 2022 11:14:14 -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=BfVj2+YbqU03eg9FI58FYBrziSuvlZ92uC4zdqn5CTE=; b=eeTKwrf38o2KUassehYgJ0SBTM5gH9nmCshgjuUEib5vc5yjGVUZKtpSaU9uf+sV1g MISr0mh8C8wZS84uPxDt7puyzqSawUtB7wmkqyVvwoOh2oLIGU2ARUtbzUCL0ADis2cB UuE0UIWNQrPj2uBw+/LT1+0Gw+q/3S6OS+Bo/MgOpKzAItHw/60jpZZ3dVW+nfiDIjdU Oze8imsamjoNCaSDDauICJS3S0udRm0yC5GvLbtx58FETBlrCIILdIeFndS8YHjY3cbJ GglltlPqPL+0gHviQnlPUEUvZ3GUWKhYbL5tU0d2IEVzGOErmsD1PUU+LdjGdGkS5UJ0 G7hA== X-Gm-Message-State: AOAM533l5gibIuIKasTZo/k8+DeQoRiu5ejcnbxa293I8VPmMk2SUScr 714Y6/yjGo2b/9033tPvMm2MJ7iVPZqqZSqSdCVtarVaoyOntxCwEvlDsn5qEk/CoNkW8VdVTrP D5943V7YaAo6dXlHNMe6MTQOS2HgJcAm4KK2IDg== X-Received: by 2002:a17:907:271b:b0:6b8:7863:bf3e with SMTP id w27-20020a170907271b00b006b87863bf3emr962559ejk.188.1645643642493; Wed, 23 Feb 2022 11:14:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJxXMYb4BEMYhrxOu6QSGckuJedkkcxoYAbkZ+2GxGDgO4kr7mPrVFflFNpyN2dv7nSCwE216w== X-Received: by 2002:a17:907:271b:b0:6b8:7863:bf3e with SMTP id w27-20020a170907271b00b006b87863bf3emr962519ejk.188.1645643642300; Wed, 23 Feb 2022 11:14:02 -0800 (PST) Received: from localhost.localdomain (xdsl-188-155-181-108.adslplus.ch. [188.155.181.108]) by smtp.gmail.com with ESMTPSA id q5sm212611ejc.115.2022.02.23.11.14.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Feb 2022 11:14:01 -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 v2 06/11] s390: cio: use helper for safer setting of driver_override Date: Wed, 23 Feb 2022 20:13:05 +0100 Message-Id: <20220223191310.347669-7-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220223191310.347669-1-krzysztof.kozlowski@canonical.com> References: <20220223191310.347669-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org Use a helper for seting driver_override to reduce amount of duplicated code. Signed-off-by: Krzysztof Kozlowski --- drivers/s390/cio/css.c | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/drivers/s390/cio/css.c b/drivers/s390/cio/css.c index fa8293335077..2ced49be1912 100644 --- a/drivers/s390/cio/css.c +++ b/drivers/s390/cio/css.c @@ -338,31 +338,15 @@ 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; + 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 = sch->driver_override; - if (strlen(driver_override)) { - sch->driver_override = driver_override; - } else { - kfree(driver_override); - sch->driver_override = NULL; - } - device_unlock(dev); - - kfree(old); + ret = driver_set_override(dev, &dev->driver_override, buf); + if (ret) + return ret; return count; } From patchwork Wed Feb 23 19:14:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 12757402 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 734D4C433FE for ; Wed, 23 Feb 2022 19:15:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237740AbiBWTQH (ORCPT ); Wed, 23 Feb 2022 14:16:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240128AbiBWTQE (ORCPT ); Wed, 23 Feb 2022 14:16:04 -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 1CD983FDB5 for ; Wed, 23 Feb 2022 11:15:36 -0800 (PST) Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.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 F15923FCB1 for ; Wed, 23 Feb 2022 19:15:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645643734; bh=7IYTHmQXzsIW766tCpVJPfNTfO+AmvxjDRcTslL8YGA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=WFCf3Jhczcxz0E4zEc6I6GxVf/fZq5M2jxZQ/Jl4UyFO6r9olBob+ly4Or9kIQ40u BdfYE/u33GjN1phHE6OAj9c0jYx3yaDkefoO+LQwGjBZjEfCyeARyqKKZ+XLWsyCWK LLgrcxhOBFkj+C/kKoSN89gCsGipSRwnQGoWqtHFuvfF/TD28nOuz3PlRgR6/Xsp/y /ERa6rFKzDKrfe31imTMGxF84TXjyQnH5PRM/Yoq9AGjQq0h8HaXctbeIZ1aYmL7Pl +uz+ndzfLE4oH6gSn2Gb0wuizad88sCfbkpeY7SYKvRtO3BH4InBDkRqKdj7jNCAPB pfoFjovz1+HHQ== Received: by mail-ej1-f71.google.com with SMTP id qa30-20020a170907869e00b006cee5e080easo7440957ejc.3 for ; Wed, 23 Feb 2022 11:15: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=7IYTHmQXzsIW766tCpVJPfNTfO+AmvxjDRcTslL8YGA=; b=i7Rl23YeQeoQ720e6YYVwNxWBydNJLAZ7b1cwMkm/5hCgGbCr0O0Ps2EU80CCKnee3 PClIq7cKcCxmb79w8BpsM3RM5j/2/+m4YU1uuyKaGKECZo1e5YhDMjQAZPI8MI+dh2CO FbGrhYLkrO7rMNObmlcIPp7U9V+G55j1jVCRNImfbeSjiLf7qDoW+ScDTLE19WlkLdzu 3EVNA5d1J1O6yG7zdwZTAs2YERE+4oupa8g25ZB/dYOTgtUZuNeevh5Pu5An6kMCYaaZ Ftv95pAF+1eZTKeb+8IUrbjHIOoX74X3507VpeMLfEZuIkC66L/+LGco/z1udj9mVoYR Rzgw== X-Gm-Message-State: AOAM53151vHLQC7KVfOR9zbl/JKsbTz7eQIPtPoWSfbxKRRDrR2QLSiG +V5h7qkKRZ+4etW9A4oAIkNqja5V7hfjJcJ8RS4UBce3rA5J9gzdUKHpvHdibSZWmJlKTwqCtga Kt7GX1PI8WDaYcDr4OD/t3KdfNddGGEq9DFMTbg== X-Received: by 2002:a17:906:b57:b0:6ce:e31a:524 with SMTP id v23-20020a1709060b5700b006cee31a0524mr898068ejg.290.1645643723450; Wed, 23 Feb 2022 11:15:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJwXaymv6Y03sx5emAtiihVKDslUlZDj5+bUOqZTX2T0tvcmba61MgF/pNNazmHUobDDFmGa2g== X-Received: by 2002:a17:906:b57:b0:6ce:e31a:524 with SMTP id v23-20020a1709060b5700b006cee31a0524mr898038ejg.290.1645643723190; Wed, 23 Feb 2022 11:15:23 -0800 (PST) Received: from localhost.localdomain (xdsl-188-155-181-108.adslplus.ch. [188.155.181.108]) by smtp.gmail.com with ESMTPSA id b3sm208368ejl.67.2022.02.23.11.15.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Feb 2022 11:15:22 -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 v2 07/11] spi: use helper for safer setting of driver_override Date: Wed, 23 Feb 2022 20:14:37 +0100 Message-Id: <20220223191441.348109-1-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220223191310.347669-1-krzysztof.kozlowski@canonical.com> References: <20220223191310.347669-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org Use a helper for seting driver_override to reduce amount of duplicated code. Remove also "const" from the definition of spi_device.driver_override, because it is not correct. The SPI driver already treats it as dynamic, not const, memory. Signed-off-by: Krzysztof Kozlowski --- drivers/spi/spi.c | 20 ++++---------------- include/linux/spi/spi.h | 2 +- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 4599b121d744..0c7e2c34f4a3 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -74,27 +74,15 @@ static ssize_t driver_override_store(struct device *dev, 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; + int ret; /* 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; - - 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); + if (ret) + return ret; return count; } diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h index 7ab3fed7b804..01224d07aaff 100644 --- a/include/linux/spi/spi.h +++ b/include/linux/spi/spi.h @@ -184,7 +184,7 @@ struct spi_device { void *controller_state; void *controller_data; char modalias[SPI_NAME_SIZE]; - const char *driver_override; + char *driver_override; int cs_gpio; /* LEGACY: chip select gpio */ struct gpio_desc *cs_gpiod; /* chip select gpio desc */ struct spi_delay word_delay; /* inter-word delay */ From patchwork Wed Feb 23 19:14:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 12757403 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 2BF23C433EF for ; Wed, 23 Feb 2022 19:15:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240128AbiBWTQJ (ORCPT ); Wed, 23 Feb 2022 14:16:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244271AbiBWTQF (ORCPT ); Wed, 23 Feb 2022 14:16:05 -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 1AB47403EE for ; Wed, 23 Feb 2022 11:15:37 -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 C6A243F1B6 for ; Wed, 23 Feb 2022 19:15:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645643735; bh=H2keAgAmU9ZqqGFkafNbZlkvfevlWycDJlQlht8xanA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=D9cwn5BL9MJVKNDemIQCrFaICpDe78PK6gdsb+A9hCiVzMCyGHUdgLj0deXkaB2UF 0FxQrL8efj7296DUz4nlCSKXDyEbXgigCxMrLXvvZWOCQLxbATRYszC5dD0BeqfkI+ QI4Sh5b8B/0uV5AHMMWEa093+qo57eXd/5Hhy5xof/yX2En854YJsMERCcsdgDraZC kzMdnKdJumVA1mq1076sgJrnBpd6e+6fk0ZKK2ndhDbFnQtLeCzMM2CnLbATXXRz0K 0SkyHI/FLIxXDtfprEo8+fn54FMvA7w3FCw87+jJ88o3MnntjALE83uHpz2aVYa+7a qezG5wWcBlHhA== Received: by mail-ed1-f72.google.com with SMTP id r11-20020a508d8b000000b00410a4fa4768so13937462edh.9 for ; Wed, 23 Feb 2022 11:15:35 -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=H2keAgAmU9ZqqGFkafNbZlkvfevlWycDJlQlht8xanA=; b=c+/nMNcZTXo/fOhpSK2p8xS00cKYYsigQpJCuz8ZseBm9vTu1Ml3bJqNuFPD+GeQz+ kqcGmTSZNaZqK3fhCLDY0bVH6XZqQMl9U+uo1P6B+rbtorELkTXBd9XEmu+KxydQNiga /X4icPz3HUFggKv9QjAR1NOuI9FdF9T8J5fMBkT/r7GPt4ELLTikeUodH4AQt46+bMit PDqurg/uHBS0pDDgkR/cRQea7IZUFZbJMVKX7iWFHNhR8vMnfN4EgmozxV8tnCORXY1G v5YTz8z0KEP9Qf/PCZVuYY5PfZ5p1c/5ZNbnkrDgpz+DRNYJ96EUt1th+S1rABmB9470 cXIQ== X-Gm-Message-State: AOAM530zq+OWriQ9+8GafVkX1Y5+iCY8mjA41VCis2Bd8B3/oHIBd1tB ZO5L/32qhH3ief0cYoEvSOuBds6F0HWUuc1zgrspFwIPPjAAucHBgKUz91c+pjFE9pMba2PuKtA uE1JxkgDjAeHI/yZwrzAFq2UAg0S8+D35JtjOLw== X-Received: by 2002:a17:906:684a:b0:6ce:c1b4:b503 with SMTP id a10-20020a170906684a00b006cec1b4b503mr894495ejs.355.1645643725344; Wed, 23 Feb 2022 11:15:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJwpQByhmcToLCr1i/g+5dfeJyrnQroTWuW6ciExOrKYOzQiErT2Fu468xjrk+1eigQXSikm5Q== X-Received: by 2002:a17:906:684a:b0:6ce:c1b4:b503 with SMTP id a10-20020a170906684a00b006cec1b4b503mr894476ejs.355.1645643725160; Wed, 23 Feb 2022 11:15:25 -0800 (PST) Received: from localhost.localdomain (xdsl-188-155-181-108.adslplus.ch. [188.155.181.108]) by smtp.gmail.com with ESMTPSA id b3sm208368ejl.67.2022.02.23.11.15.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Feb 2022 11:15:24 -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 v2 08/11] vdpa: use helper for safer setting of driver_override Date: Wed, 23 Feb 2022 20:14:38 +0100 Message-Id: <20220223191441.348109-2-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220223191310.347669-1-krzysztof.kozlowski@canonical.com> References: <20220223191310.347669-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-clk@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 | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c index 9846c9de4bfa..76ce2dcae7cb 100644 --- a/drivers/vdpa/vdpa.c +++ b/drivers/vdpa/vdpa.c @@ -77,32 +77,15 @@ 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); + if (ret) + return ret; return count; } From patchwork Wed Feb 23 19:14:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 12757401 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 B2719C4332F for ; Wed, 23 Feb 2022 19:15:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238888AbiBWTP7 (ORCPT ); Wed, 23 Feb 2022 14:15:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236973AbiBWTP6 (ORCPT ); Wed, 23 Feb 2022 14:15:58 -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 E3568403E8 for ; Wed, 23 Feb 2022 11:15:30 -0800 (PST) Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 47DBA40814 for ; Wed, 23 Feb 2022 19:15:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645643729; bh=WWBR/3RyyId0ctzqGYcSjorUZAyYEVp2bjQXWveQ/28=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=G3aWHWf5OfhGUIVQqjn8G+xNBfCnBKB07GueZlhBJ1IvCUB3eD++APC6ZXGyFhOWG 5xMPqJdAfdoOPf4y0wDChBifJfbj3uanvWgHNcYvc1sRXuyxpBbXSiMZro/via8j7T oqKGzZI+QsuI0iBYnSBFbn4j4iJ8JPxT94nQi2otrf9LZqQFgsSHG26pOAyZB/ig7B wmk+LdIFUCqpVVVQcAU33lYBf4jIT7UFsQDYAPMu4xdAH/4498n4Z00wXox5w3kpa+ ESCN3zsJBJwnMrN+4tISySBeio/kXl1TbncRwcbDun+CnV9bYO/OM+tZjem+Wv6Ppp D+fnNGYb8+lzQ== Received: by mail-ej1-f70.google.com with SMTP id k21-20020a1709063e1500b006d0777c06d6so6600854eji.1 for ; Wed, 23 Feb 2022 11:15:29 -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=WWBR/3RyyId0ctzqGYcSjorUZAyYEVp2bjQXWveQ/28=; b=2/6lhS9r4QypoewOaDOzS6Uudmj1UmA3LyGMqN4CUeV9YwjVQa6Olx1NLUNC0Fqg2r O6+TQzUjoCcwX4/SbU6oWHpj1EkUZyltmBLkJeDkpMduHCcOU0bh2ubO/VqliYVaK4p2 THdMCk5kgavNsiISYTaW/hqz614DkR/B3V/+DmhycITB7SVyNRWz0K4M1x1IAcOGBw+7 /W46Ni56YmQKNCgOrWKU8MFonOqxes1vGi5kLJsEt+Vm7bZxXfP/4DGhl7YsfWC/gNso 34QuRIdAQEyAGcK7irbbGHR44xutI9h1Uvg5pOBRdcscW1h6AApO1WVMeJZThhHuXFGq 2aNw== X-Gm-Message-State: AOAM531Xfym6areCD6+vZBFkAC4qiJg+vuLFAbdpJEyxhGO2TW9fRuPu gV4QSS86lAb6KxVKR9nliSus+xEVjlVFZ7kyzYg3lleg5XMlof6/P6GphPg7QHa/yyfF5U03SPp D8SBR7xv42wAs6G9+kbgoCDwXa/MVrS+bsrMWMw== X-Received: by 2002:a05:6402:70d:b0:410:ba4d:736f with SMTP id w13-20020a056402070d00b00410ba4d736fmr891824edx.0.1645643727229; Wed, 23 Feb 2022 11:15:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJw8vcySNYfbv43Pk2WXynTAOxXboVgUUSRQKZSxFWxW+kHULs5hedJTU2eFScz4UFZao2eyYQ== X-Received: by 2002:a05:6402:70d:b0:410:ba4d:736f with SMTP id w13-20020a056402070d00b00410ba4d736fmr891811edx.0.1645643727044; Wed, 23 Feb 2022 11:15:27 -0800 (PST) Received: from localhost.localdomain (xdsl-188-155-181-108.adslplus.ch. [188.155.181.108]) by smtp.gmail.com with ESMTPSA id b3sm208368ejl.67.2022.02.23.11.15.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Feb 2022 11:15:26 -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 v2 09/11] clk: imx: scu: fix kfree() of static memory on setting driver_override Date: Wed, 23 Feb 2022 20:14:39 +0100 Message-Id: <20220223191441.348109-3-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220223191310.347669-1-krzysztof.kozlowski@canonical.com> References: <20220223191310.347669-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-clk@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..15e1d670e51f 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"); + if (ret) { + platform_device_put(pdev); + return ret; + } ret = imx_clk_scu_attach_pd(&pdev->dev, rsrc_id); if (ret) From patchwork Wed Feb 23 19:14:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 12757405 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 4E617C4332F for ; Wed, 23 Feb 2022 19:15:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244306AbiBWTQU (ORCPT ); Wed, 23 Feb 2022 14:16:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244302AbiBWTQN (ORCPT ); Wed, 23 Feb 2022 14:16:13 -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 D702D427CA for ; Wed, 23 Feb 2022 11:15:42 -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 2B67540814 for ; Wed, 23 Feb 2022 19:15:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645643741; bh=oRXS+YkCrSg6HXmKQBekF6bqmCpfytEa7gv0higjFpc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=JobDBzDiCP916Vk1VG+o196YKLxDfzLsmm5cKNJFB8uoOSe8a1ocD4lKQOKPqAzZy iLIBskw/lGrW/JCYPfKEQ3Njzqt+k43JAI+C6cmGS6v0Bzd80G4yFMeLLaIDFF6eZs 8gaXFVvUNVWJrmuBJYUP+FxP9kbzkgB2JkjXrA8hkxYexdjGiV+8+aYvqt6I7JdSTK qRxeNp3a8/LiEmlxsbrjd8rOi+lMT1H2eS85g7Ct7tsF6UqgRl1Efs+1swd3zi3rfH VEWvCKfOgfWzR7QhXI/fc+Cgq2CunkYlUaV4uIsNlyY63uGOiGBHqUzbQBZKJWdfRt udKhhaxKcAzLg== Received: by mail-lj1-f197.google.com with SMTP id v5-20020a2ea605000000b00246322afc8cso5892017ljp.4 for ; Wed, 23 Feb 2022 11:15: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=oRXS+YkCrSg6HXmKQBekF6bqmCpfytEa7gv0higjFpc=; b=LYKbLhE4cFdMgMRyx5ByI8uhPULLpORQxs4ppWgaYKd77Zu0X/9Ir6qJIYwiEVf1nU 5JAGNb44VD7Dw5s9srS7JFYaMj7IwF6bsxKn8bv4bGdmbEv0VeBvCOOIAhGqE36KETa/ grzJIMjTCk/q35229d+k8DcmpY4Vt+G6DU+KeS24hxL+y4V3908pHJiUY5qmNfc3/8eD CQaNmkFLIaa/QyxgUek+O9+snlTgzNPedSTFaRMboTrgs5n0g6ZUgWONO/5pNv5CvxCq 4QP0YACc7BkditIrLmpgYukA9ZGmVa6p14ElX+wXixvGfQNDHZ8qEbIr3lVY1FaXSRJ7 2hyg== X-Gm-Message-State: AOAM530utzrdKS0oU3MYpfsR5swlmAR4/icLpfxr35tyf9pVmZjdIiyi x0ddNq+ot2gI9o7YbR7MuCzgIkP5ud65mCyWby4V0QEmLV0OMfKSaWyhHxLS6AzsslMS/2jKfX8 EF2cJ2QLhzOaSRFmU69adMbz8vmoLShc4ZSnjhg== X-Received: by 2002:a05:6402:3487:b0:40f:fa53:956c with SMTP id v7-20020a056402348700b0040ffa53956cmr894428edc.22.1645643729011; Wed, 23 Feb 2022 11:15:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJx5CjazTLBKPiBmuMFKmO+Lmp6CQ3NgkMty7AAh8YmijE7P+oo2dQqmhFhNHN6v7AVbA25vYw== X-Received: by 2002:a05:6402:3487:b0:40f:fa53:956c with SMTP id v7-20020a056402348700b0040ffa53956cmr894395edc.22.1645643728802; Wed, 23 Feb 2022 11:15:28 -0800 (PST) Received: from localhost.localdomain (xdsl-188-155-181-108.adslplus.ch. [188.155.181.108]) by smtp.gmail.com with ESMTPSA id b3sm208368ejl.67.2022.02.23.11.15.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Feb 2022 11:15:28 -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 v2 10/11] slimbus: qcom-ngd: fix kfree() of static memory on setting driver_override Date: Wed, 23 Feb 2022 20:14:40 +0100 Message-Id: <20220223191441.348109-4-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220223191310.347669-1-krzysztof.kozlowski@canonical.com> References: <20220223191310.347669-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-clk@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 --- drivers/slimbus/qcom-ngd-ctrl.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/slimbus/qcom-ngd-ctrl.c b/drivers/slimbus/qcom-ngd-ctrl.c index 7040293c2ee8..e1a8de4d41fb 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,16 @@ 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); + if (ret) { + platform_device_put(ngd->pdev); + kfree(ngd); + of_node_put(node); + return ret; + } ngd->pdev->dev.of_node = node; ctrl->ngd = ngd; From patchwork Wed Feb 23 19:14:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 12757404 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 1BE9AC4321E for ; Wed, 23 Feb 2022 19:15:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244299AbiBWTQT (ORCPT ); Wed, 23 Feb 2022 14:16:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244313AbiBWTQO (ORCPT ); Wed, 23 Feb 2022 14:16:14 -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 CC605427EB for ; Wed, 23 Feb 2022 11:15:43 -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 AF92A407AA for ; Wed, 23 Feb 2022 19:15:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645643742; bh=7X8ZF+SfQI2ha/R62opt5Mpi3EJQ2IXnqtdf8o/szaw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=v32YP2a/sT/GzRfmmvx1BuJtYM7EJWo31JUmsdlNu39fw7N0rlIb+QTtUMb4uwry3 DkSrYtQSEh04yMU2MSEY8y5HDd/jqe09HY3grFC6VzppcpChGz/jL5j9imgNnksbsY d7Kk6AA4zku//iteTYeK4o4gF3KrbWgCuMnC3RuSweTXdo82HTEgZAVsLDnYesGFaQ +TJ9346tSN/YVQjS/g87DSeAEXpEZvWn9Kt4hfElfz6I+S/ecs/Nt9/PlO32nEj90B UGjya4xoyCTKNXgV21X6RKqm/r/P3WAF2kiKle2NaLv916R6mABWplH2K/yfnc1d3k VKexoM89m1F1w== Received: by mail-lj1-f199.google.com with SMTP id n9-20020a2e82c9000000b002435af2e8b9so7755399ljh.20 for ; Wed, 23 Feb 2022 11:15:42 -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=7X8ZF+SfQI2ha/R62opt5Mpi3EJQ2IXnqtdf8o/szaw=; b=2DjBewXLoftS+fVFGh+kdbxaGOeHP3OL7oeLoh0GGdAIBtBJtRTTw/Fh8+QTM1DBqt VuXTdhfe0qRPRIn5Huf63odX5GRNZAl6Xj2vH6JZye4gpMmdnLuhclDV6iBy25F2Vrcf rE/kT6TlUxLoKtn/9NCl7D8K0WPvrouj3W+wrhbt8fWupBO2YaA1jDXIHW7p97mm8mqz FIR4gkme9xBGE72RmvcdXy6D6EIGiJeeg0GIeIB6yb7Vezx/FypcgyJ+NmHsssH8s3ws U9of+Sn+jmD5Rao5W1TnQYAw5Zq6dPYKB5pLblmEWlkCdRl43F1pt0OE3F6nDfJ8TUXz Pyyg== X-Gm-Message-State: AOAM5336F444bvIjjDKdNj6ZL6NRgIU++bqBQ+3U1ZS46n+PmiXo7jmH WQWkd4SdKG8ffVqDAWggA4fTld/Nb9WbEOeQA/CyLEFRMJi7eqXLtMTkbuylIbEb6wQggPgBzmS FMxPoOC1w6vHkIwz10bHtMVln1ZycsYXLza7BrA== X-Received: by 2002:a17:906:130a:b0:6b7:5e48:350a with SMTP id w10-20020a170906130a00b006b75e48350amr887364ejb.184.1645643731007; Wed, 23 Feb 2022 11:15:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJwzAUHN+IckyCUDaf6b+egXxiKcwH4G6el1z4Ve3vQHF0MnEv7U39pYdE62mAB1vpTAj/GhtQ== X-Received: by 2002:a17:906:130a:b0:6b7:5e48:350a with SMTP id w10-20020a170906130a00b006b75e48350amr887325ejb.184.1645643730755; Wed, 23 Feb 2022 11:15:30 -0800 (PST) Received: from localhost.localdomain (xdsl-188-155-181-108.adslplus.ch. [188.155.181.108]) by smtp.gmail.com with ESMTPSA id b3sm208368ejl.67.2022.02.23.11.15.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Feb 2022 11:15:30 -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 v2 11/11] rpmsg: fix kfree() of static memory on setting driver_override Date: Wed, 23 Feb 2022 20:14:41 +0100 Message-Id: <20220223191441.348109-5-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220223191310.347669-1-krzysztof.kozlowski@canonical.com> References: <20220223191310.347669-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-clk@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 --- drivers/rpmsg/rpmsg_internal.h | 13 +++++++++++-- drivers/rpmsg/rpmsg_ns.c | 14 ++++++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/drivers/rpmsg/rpmsg_internal.h b/drivers/rpmsg/rpmsg_internal.h index b1245d3ed7c6..c7bd0a3c802d 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"); + 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..1c9f9cf065b0 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"); + 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);