From patchwork Sat Mar 12 13:28:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 12778830 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 11ED1C433EF for ; Sat, 12 Mar 2022 13:31:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=e6IulbzpfGLCZAqK3wrP+y+wPHLbdjAZAd4qoiqwqm8=; b=if7aTErRVV+cJW wQvp4Yl7HX7j5i7jXxpMJQbNagRj1VGOl9RwABsJKGQYrY1q2wOZmGCxT5LntlNRbt5QRqDsa0r6i o09bm9h5rTN5oMiwIAJgFW+SWJgK+IwbqO06yCbLyPNsHA1kUL6MpH4JCPzFSmT3VwPoLXbXWGUZW 1ukPyliYubDLdXktrh0BjpWsQTQPQoKdMpUHsHKUpN8kM6nmN1qeONVP1pgQ/dzOin/VgRd7F+Yq1 4Ig5UZNO/a7fuGG0bDBDHpAOjiPVmg9SjBStYLurEvxwyPUBBlHhAS7HcuNoGzn/6/6aGkaLUap7N OVveeQThUTUlsAy9xl9A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nT1os-001Lq4-Ey; Sat, 12 Mar 2022 13:30:07 +0000 Received: from smtp-relay-internal-1.canonical.com ([185.125.188.123]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nT1oD-001LUQ-3v for linux-arm-kernel@lists.infradead.org; Sat, 12 Mar 2022 13:29:26 +0000 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id DD0053F321 for ; Sat, 12 Mar 2022 13:29:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1647091760; bh=LvGhGHRX+cWouXlMRKBzVPzfChdflKFXN6IyahVuGew=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=mQzCZMqMcgRgJ3+mtdvcvzl8FsQJ5bEz8/z8jH8algJzna84bUgQTC4wMGF4QQ8ma EpJ/XVf76N/BME/xdDrA0owG6DAs6mTtBpSMlElcXG71TfEYf5uZYWxjj2t/W9lASa NFbMAYadldmrlucQ1WHLMfkK43V0YMaRqmSgAsVVaPufeRrjr8wenR2t0N3/m5MbM2 RO7gXKZKqneB8L2ALOo8SYS3CP3awDPfv5UrjvkWbP+9fH2412xZSkID7HQMpcXlK1 U+Kq+LaQugjmmpMu3gd9xHtW1tL/O3d++UIxmzkhqUebRZJMZM5pFwA2E4uTxgc9/k EkGUID+PRv73g== Received: by mail-wm1-f70.google.com with SMTP id v125-20020a1cac83000000b0037e3d70e7e1so6910308wme.1 for ; Sat, 12 Mar 2022 05:29: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=LvGhGHRX+cWouXlMRKBzVPzfChdflKFXN6IyahVuGew=; b=MwCUh4S6wIF0l9TN97CRSBKRCLBqexJt74gonhm+WRlQQ6a8IB6aEOFotZtysCsNKz aNR8Bkv6jznGMwpPDwp62KtZOXYgHzEgMEwVPk+cmjv9vm+94Vk+AfvQW8xvlTChHfla 0ARrCcEixRbl54Uq8dn1/gNXgVkV2Wad6pX92h6SGVjCI/czgLuO5twNkk9eJR25+RE9 HUxJ9kO0ppsCoVpEvmyed6LH0AdfifQ6qhgtV745zoi0lBtJUH99XJRODdCIAyageo0i LhPSrPvS29fFVfiNPir0rXKGWf2AVN2Qb79C3ffPb4WP/wdnYg4J2JiHQk6qm77+PfR6 R+Pw== X-Gm-Message-State: AOAM53252wu/GtBwvxH4Klbso2Nm62BMAL7MZCsXshzjVRzZVrx5NcGI VH+PelUplhIRjboYDPxrKh/Q1fLQ9kIvCz3dBVJ5vxc946UgEFX9mo8SI8jVfMV9jCazPuJKFjN uc8NY56XABY9lguZJXJd73ODsjN0X71/kdhf1oU2W1v0IhemFP7MA X-Received: by 2002:adf:c444:0:b0:203:9078:47a7 with SMTP id a4-20020adfc444000000b00203907847a7mr8545382wrg.355.1647091758528; Sat, 12 Mar 2022 05:29:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJxcbUuA5Azax9SMwrH1Yx4BInTaqxjL2pAuKiWGJSR5gaJ62UjEiFqy7nmiSZn+2WWM/iG5SA== X-Received: by 2002:adf:c444:0:b0:203:9078:47a7 with SMTP id a4-20020adfc444000000b00203907847a7mr8545367wrg.355.1647091758331; Sat, 12 Mar 2022 05:29:18 -0800 (PST) Received: from localhost.localdomain (xdsl-188-155-174-239.adslplus.ch. [188.155.174.239]) by smtp.gmail.com with ESMTPSA id p22-20020a1c5456000000b00389e7e62800sm5751550wmi.8.2022.03.12.05.29.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Mar 2022 05:29:17 -0800 (PST) From: Krzysztof Kozlowski To: Greg Kroah-Hartman , "Rafael J. Wysocki" Cc: 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 , Rasmus Villemoes , Krzysztof Kozlowski Subject: [PATCH v4 03/11] fsl-mc: Use driver_set_override() instead of open-coding Date: Sat, 12 Mar 2022 14:28:48 +0100 Message-Id: <20220312132856.65163-4-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220312132856.65163-1-krzysztof.kozlowski@canonical.com> References: <20220312132856.65163-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220312_052925_326521_04D67938 X-CRM114-Status: GOOD ( 18.31 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Use a helper to set driver_override to reduce 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) \