From patchwork Sat Mar 12 13:28:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 551101 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 alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (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 6CD57C433F5 for ; Mon, 14 Mar 2022 07:07:31 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 889CB185F; Mon, 14 Mar 2022 08:06:39 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 889CB185F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1647241649; bh=XJnMSjYTtnNNa5Ny/BXTnZMGBygvP/u91rN/XUBBplA=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Qp5HU8911/2gqNePJhj9wkgkVSX2CLjd+UlbKnhvEfVweSU+50yWUfN7szrE7Z9Ua wcO5l8l7S7d74oa3SL3hEM99+Sk/vWEALR3tWu/ldiKWnjZJF7yfs66wsokdmxNKE4 zd8EJCJ18Hcc+oidjhSbpHJGc31VMSq69A1UorQA= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 2B863F805D6; Mon, 14 Mar 2022 07:59:26 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 9F29CF8027D; Sat, 12 Mar 2022 14:29:38 +0100 (CET) Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id AC380F800D2 for ; Sat, 12 Mar 2022 14:29:32 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz AC380F800D2 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b="Cd/jriyb" Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 5E36C405B3 for ; Sat, 12 Mar 2022 13:29:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1647091771; bh=Fv0wjNs2b5QtUq9euXNEr2b5kaqy1J/ffW8/38DamY4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Cd/jriybVCnYNDZa2LHjnuMtabf5H1tXszwxqpnm45s9u4PI0MYxczPyUyEO2U0g9 j4uRe1QoEkU6XgKJczLiEadFXq3nfJKAVwTqGFa/G/0UKamM2RY6rbFr5EOdwQuErc b2lJwGgKnQtO+kvVoQ9457OB9Xzx9HISeU/lO4qOVYHwFGAWHUwfT0wxZWopeJfDbu ZTvNlOkMvjImko7/40yx9lk7v6m1UD7S2Pbo6HuKhotOU7Kxlsmfnfl3cb2EHB7gEO 0Rykz55Kj9BwEOnQ4TeyRxbpjTlGzHwB3Wwa6ghKvoILhfCqCF4YFUnvOz9PaFxwad CObkn32Q3PQLg== Received: by mail-wr1-f71.google.com with SMTP id e6-20020a5d4e86000000b001f045d4a962so3732794wru.21 for ; Sat, 12 Mar 2022 05:29:31 -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=Fv0wjNs2b5QtUq9euXNEr2b5kaqy1J/ffW8/38DamY4=; b=bShbQSPezXHxU+5dCCJ6bfJFLlI6DNBJJzEx+fardSWIDv7QINkvWqsE+/fbve9DR9 CigTfcNsvhFA/tgv/TSW3js//usrLjOjgPW1Pl6dTkpc1cDxgQpxenlp1JDeTMPe8kVm e4xhj9XQfxyXAn4JXRhfXj9IGHWu1rx8fpPN5zhTe/JORorMXh9/SUm3EywGddwHbSOU pZGzHIndasRB46kuB5zNP06JItTuCnzuHFZtx1Yqz5V3427zaMSiJAeO2E9furRPoMAS iAwNt2SBwMb4QaTjYpGcSbb2LOFISfvR5dT9cSFZEYuBGqwWH194p/ksn6gNZbEMV88I Qkrg== X-Gm-Message-State: AOAM533duZHmrrp5hImxgwUQGISwmbwkp1mETQd95rSwTlgfGhMu6QpL mt2RBJ3VbW6oJqYa/nKkEjXryO/PfLJTrdb4atAHzdHDt0TVMJoKD0hzz+PyjeLWy/3Oa3zP/Y3 PkHhL5xppBfnH3pegHJT1sIjGpT2ghumzS9jw2gmj X-Received: by 2002:a5d:458b:0:b0:1f1:f876:48e2 with SMTP id p11-20020a5d458b000000b001f1f87648e2mr10681297wrq.76.1647091760271; Sat, 12 Mar 2022 05:29:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJyDBzysSy5dJPpClWLlHuYPvBegFX8iikOsVYCIkiLzfLC7xpzwCpZjF6/7zZtW5qI29WBIOg== X-Received: by 2002:a5d:458b:0:b0:1f1:f876:48e2 with SMTP id p11-20020a5d458b000000b001f1f87648e2mr10681251wrq.76.1647091760021; Sat, 12 Mar 2022 05:29:20 -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.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Mar 2022 05:29:19 -0800 (PST) From: Krzysztof Kozlowski To: Greg Kroah-Hartman , "Rafael J. Wysocki" Subject: [PATCH v4 04/11] hv: Use driver_set_override() instead of open-coding Date: Sat, 12 Mar 2022 14:28:49 +0100 Message-Id: <20220312132856.65163-5-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-Mailman-Approved-At: Mon, 14 Mar 2022 07:58:51 +0100 Cc: linux-hyperv@vger.kernel.org, Stuart Yoder , "Michael S. Tsirkin" , linux-pci@vger.kernel.org, Jason Wang , linux-remoteproc@vger.kernel.org, alsa-devel@alsa-project.org, Bjorn Andersson , Srinivas Kandagatla , Vineeth Vijayan , Alexander Gordeev , "K. Y. Srinivasan" , Fabio Estevam , linux-clk@vger.kernel.org, linux-s390@vger.kernel.org, Wei Liu , Stephen Hemminger , Abel Vesa , Krzysztof Kozlowski , Dexuan Cui , Andy Gross , NXP Linux Team , Christian Borntraeger , Heiko Carstens , Vasily Gorbik , linux-arm-msm@vger.kernel.org, Sascha Hauer , linux-spi@vger.kernel.org, Mark Brown , Rasmus Villemoes , Bjorn Helgaas , virtualization@lists.linux-foundation.org, linux-arm-kernel@lists.infradead.org, Laurentiu Tudor , Michael Kelley , Mathieu Poirier , Linus Torvalds , Haiyang Zhang , Peter Oberparleiter , linux-kernel@vger.kernel.org, Sven Schnelle , Shawn Guo X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" 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 Reviewed-by: Michael Kelley --- drivers/hv/vmbus_drv.c | 28 ++++------------------------ include/linux/hyperv.h | 6 +++++- 2 files changed, 9 insertions(+), 25 deletions(-) diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c index 60ee8b329f9e..66213ce5579d 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c @@ -575,31 +575,11 @@ static ssize_t driver_override_store(struct device *dev, const char *buf, size_t count) { struct hv_device *hv_dev = device_to_hv_device(dev); - char *driver_override, *old, *cp; - - /* We need to keep extra room for a newline */ - if (count >= (PAGE_SIZE - 1)) - return -EINVAL; - - driver_override = kstrndup(buf, count, GFP_KERNEL); - if (!driver_override) - return -ENOMEM; - - cp = strchr(driver_override, '\n'); - if (cp) - *cp = '\0'; - - device_lock(dev); - old = hv_dev->driver_override; - if (strlen(driver_override)) { - hv_dev->driver_override = driver_override; - } else { - kfree(driver_override); - hv_dev->driver_override = NULL; - } - device_unlock(dev); + int ret; - kfree(old); + ret = driver_set_override(dev, &hv_dev->driver_override, buf, count); + if (ret) + return ret; return count; } diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h index fe2e0179ed51..12e2336b23b7 100644 --- a/include/linux/hyperv.h +++ b/include/linux/hyperv.h @@ -1257,7 +1257,11 @@ struct hv_device { u16 device_id; struct device device; - char *driver_override; /* Driver name to force a match */ + /* + * Driver name to force a match. Do not set directly, because core + * frees it. Use driver_set_override() to set or clear it. + */ + const char *driver_override; struct vmbus_channel *channel; struct kset *channels_kset;