From patchwork Wed Mar 16 15:05: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: 12782836 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 6B94FC433F5 for ; Wed, 16 Mar 2022 15:09:33 +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=WdOhad+uFjOcKka35AXbODg5EV3rnzjntSe6snrv/kM=; b=sHXKoVdzEAMYxY fcAWC/Fxd+J1v2ZcZyOX/476cwu6PQKDLr7EeR6lP8iWOJ8aZGIMKSZxYliHBrNJo5UlYlzjfyAcg 1qB6aPBUaznkuPmwVR6KFu+2pynFlBLHj4zJpqWr2qTAl1vPWDGS9aUDPVQjBOPKYKgoAnfN+h11f 7GJINUakDzufNcFQaT7hFtwxOyIwP0iXsh0vLPpPTwxNPfvLaDoAHZtl6mIfGT3FBLsdBnm/qJaGD wH7ypRi/agbdNa2A7bi21jcdP62RE9rBFFuTuV4jbAJ2drrTRupmGM+1hQggAwmWKcAQbKc9CExth oz3yW7/QDSkDBNGi/3Kw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nUVFg-00DPZM-UN; Wed, 16 Mar 2022 15:07:54 +0000 Received: from smtp-relay-internal-0.canonical.com ([185.125.188.122]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nUVEg-00DPAW-R9 for linux-arm-kernel@lists.infradead.org; Wed, 16 Mar 2022 15:06:52 +0000 Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.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 8832D3F1AF for ; Wed, 16 Mar 2022 15:06:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1647443209; bh=qe4dhnprNWM6uzn5SGQYSUaT3EAa0OIFZFVGuX4NqAE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=vE57SmuIgdMCDxbOpz0yHOe4anylRKMJQPNUqWxC8xJkqt8EiR44U2uxbhyHSQKe0 LEIaEFxmt+a1LaCdre5kebd0QnpnW4AhDXsaU4+RJFSbomUfceYoEMunpRILSL3Esd +PxAxRHJ4wFfkAsgSPG6dBP28ArQeQZE+hcLoG/Lbm4y1R/eqa31DPkhMQVEKQCj/p eHCWpgRbe6APd7tSz4kkmoY+x/lMB2ViNQb3O6O4GpKeSizsD22HIvIottk1Tat9jG Z49ZlI5Owgq9ga+B7WrfFOTOzek8a/XuKpQzAUejTSMZ8GpR3GlrUwoL7y+CfkQoM3 dm7Vz7f3ET1aA== Received: by mail-ej1-f69.google.com with SMTP id i14-20020a17090639ce00b006dabe6a112fso1309153eje.13 for ; Wed, 16 Mar 2022 08:06:49 -0700 (PDT) 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=qe4dhnprNWM6uzn5SGQYSUaT3EAa0OIFZFVGuX4NqAE=; b=7hCcf/Ym7wvdvCuw+ppFMH2kQulztrLyUeMQHrbWj4DgfksuYXRBik5wTZsq31AI1D ZoeYxmV2HSSwiCU205EPs/waGex/VTR3CjnsDI9yghyVE6MFFkyV8kgscDQxoEunmB7j 1ZH31y2X1RLy7/Escs/RrK14T9Vs5QbKwdMBiz8Hd6uudMvMk65eGdjrjcTtIk0Hy7Io ZBaa++WGoeZYCrE6D7+gauzafeqs6aVF/uOWGXsVs26LlRdLEopH6PNr8ydT7W5uKYxE jbGUR4bzJzoKe8sa1x40tPTPGmtJcogO8NIz9n/1+hPLNV7YCyocVblskHID92O9anhR IMjg== X-Gm-Message-State: AOAM530WrEm7zYJfp1lqBFr8PO7HAFkVctzRatxbWsJht6ky+w2lJg2W 9DxpnEhQEKix2WUMjBXhEEy0rnS28l77qInHD4mhP4DK78+jsRekdJi60TOKJFRGU4/4waprnm2 VAULiNLLJ7k/lxMqFcVfgeGHBFkMeV1RlGFbMA4u4rrBru4HSRFa/ X-Received: by 2002:adf:f48d:0:b0:1ed:e2d7:d5e0 with SMTP id l13-20020adff48d000000b001ede2d7d5e0mr339346wro.252.1647443196957; Wed, 16 Mar 2022 08:06:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwLiBCbgm6QRK3G0rpLKvHnouae5z5SEdfWjFsLkOL7izSJ06dvAGkwNICqtwmEJDwxDDgSbw== X-Received: by 2002:adf:f48d:0:b0:1ed:e2d7:d5e0 with SMTP id l13-20020adff48d000000b001ede2d7d5e0mr339317wro.252.1647443196762; Wed, 16 Mar 2022 08:06:36 -0700 (PDT) Received: from localhost.localdomain (78-11-189-27.static.ip.netia.com.pl. [78.11.189.27]) by smtp.gmail.com with ESMTPSA id p14-20020a5d59ae000000b00203dcc87d39sm3130155wrr.54.2022.03.16.08.06.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 08:06:35 -0700 (PDT) From: Krzysztof Kozlowski To: Greg Kroah-Hartman , "Rafael J. Wysocki" Cc: Stuart Yoder , "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 , 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 , Andy Shevchenko , Krzysztof Kozlowski , Michael Kelley Subject: [PATCH v5 04/11] hv: Use driver_set_override() instead of open-coding Date: Wed, 16 Mar 2022 16:05:26 +0100 Message-Id: <20220316150533.421349-5-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220316150533.421349-1-krzysztof.kozlowski@canonical.com> References: <20220316150533.421349-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-20220316_080651_049687_F382320B X-CRM114-Status: GOOD ( 17.99 ) 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 the 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;