Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp2083838pxm; Sun, 27 Feb 2022 10:48:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJzBDcEufelgNafVWCNAwBBGnlqHFUIotU8g20BsK/8GLWRXpUBISaBFPzU9CmpFFAT0PWMl X-Received: by 2002:a17:903:41ce:b0:151:3a3b:fe80 with SMTP id u14-20020a17090341ce00b001513a3bfe80mr11229189ple.83.1645987727631; Sun, 27 Feb 2022 10:48:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645987727; cv=none; d=google.com; s=arc-20160816; b=pSJTB2XF/enxPVdVVMxnHsXmhfxCm7Xx3cDwf5kgZMTF1RJAZRdoHtHlg4uRm2PqFz QnmL7lk7NVLO91P4/SU9QR/v0flKEAg9E3pZBqe0hEiQBkUkmvo48dCKUIf5ZEQOHgsM 3GssUmgzAbCUgc46CjmLzaHxtvaPeRotXnUPFGEr/bB5aKdf1Aa+v4+xPd6mybeFAubx HxlOMsCtscgw0OqbqE0CKEJIFADJL1eRCNVLTspPEH2wVx8Knc35yBgamSOaFITfOfsz 5KjKxFZeoQ+Jqy9Wj26egDlQXahJLJPwcL0w8O7Xfu6HNBUa+1JuRXQzBZd7UKlOj4ry NrDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=pRyoy0wYqVh1vMWkfgiwvfL+uC0PF+MUz+uOlTyWlM0=; b=L3n8KAL6HtUZyBSzcfApXuLMvQcFyHJ40Ex4aA0QPUKMl5+YQaSQv3tFZJl+PEzUkf 0ZjW8XrQU/lsTw+P2gp06VRwSE43MPJBZOzbB0EVLJDbzf4lHKFETE2hKccQe/Eu1HEc LnjVw/3BwTK/j4V8jQyAU4T5+yGgUyW9/mRkBeY+CY83zXIy0tckn6Mvk+LyE5fIfwJY sygCzgvbaGvGX8VcdSy/cZtv+H7HmvDzkvd0edF+ueJmKNNzdx7aS+rdy7NAvTl6vHew MtsaV7oJHdKDAbcpiEPVHUdCQ6ed8j4aU8tLF5LcD/sObH0xd55xkdYTaqu/xCpsjvrY xZXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b="S/WVfEun"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v17-20020a63ac11000000b00373d43f3842si7625494pge.492.2022.02.27.10.48.31; Sun, 27 Feb 2022 10:48:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b="S/WVfEun"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231375AbiB0Nx5 (ORCPT + 99 others); Sun, 27 Feb 2022 08:53:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231274AbiB0Nxf (ORCPT ); Sun, 27 Feb 2022 08:53:35 -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 1001113F85 for ; Sun, 27 Feb 2022 05:52:54 -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 4FCB54031B for ; Sun, 27 Feb 2022 13:52:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645969971; bh=pRyoy0wYqVh1vMWkfgiwvfL+uC0PF+MUz+uOlTyWlM0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=S/WVfEuncOULSzfdfmuwsoVoS4r8vAvDttCNWqP1wmxKmVTJUNClkPsErnGdvbACB AUFBBtoUCh4QV7kl4EHuW7uzB+1qRJ3UGkPrrZBk6QJCPFbc1CY7SnoPaoY4Ge/bbN iNaSNIjy0k3mumJy6kKgkzHVGRBjhzGZ7TAyEmP5yzkBIuciKWgh/6xH6AMUmPgCsl yAIbNU4+AwE9DkcC529plcD+MFnrRr1Pb4xGTTJZ/HlR5FyvWmUNggGwHkNmnmU9Jp GVxGW96uanFOUHp2k0H9QOQmQYcr+dKIt8Moz5XXhAN3ywAASPbo9GmoQYuMCB5pg/ zY+kOLBYG86EA== Received: by mail-ed1-f72.google.com with SMTP id e10-20020a056402190a00b00410f20467abso4240418edz.14 for ; Sun, 27 Feb 2022 05:52:51 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pRyoy0wYqVh1vMWkfgiwvfL+uC0PF+MUz+uOlTyWlM0=; b=jX0LyiaRhMyc0w7gHcW5uPmog5AzG9lKwDJ9pbMMocpCU5/ONqZW2b8ey1msr23NVD gfr49LTxp82JrvDp5K0BzhMX4aO903UCl7UqzLleuPh5KiJ7YxLWJGVvZLn8VzpyFBvc kz16SAQuEWqMH1NzQT3Yd9jhBI10K89mpjnJWdHVaaZFWiuVi9wMwMWxGDaVSEFf9euE DpyplXQq0zY0+/SYJgLf+89Ad35rKtMJ07DNlfNhTPCAH1lo5Ux7LHP/AjBgj2axAaNj pH12M5JNljj6FDtfhFRtSULvHWvCtZtyAxdKs7/SwZqIjyZGaQxUi7MJJXS91u0hCl2L JE4g== X-Gm-Message-State: AOAM532uUA54ikbqadZ7j5OfiT/axVzcel9u1zRkLnRSdmEyNAMP2Y+q oIhaM+lI9RpgGY7J9n9DETACbOfmSPML9SEQ3DHe5HJl0Zwi394yIofDYpicT2Fq5eQc8t++EqQ pRTlYEOEk9BBnKYvtlkd9WwPLSw9h+/sZBjm/znA/0A== X-Received: by 2002:a05:6402:1a55:b0:410:a4b4:2a9d with SMTP id bf21-20020a0564021a5500b00410a4b42a9dmr15356222edb.45.1645969957664; Sun, 27 Feb 2022 05:52:37 -0800 (PST) X-Received: by 2002:a05:6402:1a55:b0:410:a4b4:2a9d with SMTP id bf21-20020a0564021a5500b00410a4b42a9dmr15356182edb.45.1645969957475; Sun, 27 Feb 2022 05:52:37 -0800 (PST) Received: from localhost.localdomain (xdsl-188-155-181-108.adslplus.ch. [188.155.181.108]) by smtp.gmail.com with ESMTPSA id r22-20020a17090638d600b006d584aaa9c9sm3393333ejd.133.2022.02.27.05.52.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Feb 2022 05:52:36 -0800 (PST) From: Krzysztof Kozlowski To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Stuart Yoder , Laurentiu Tudor , Abel Vesa , Shawn Guo , Sascha Hauer , Fabio Estevam , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , Wei Liu , Dexuan Cui , Bjorn Helgaas , Bjorn Andersson , Mathieu Poirier , Vineeth Vijayan , Peter Oberparleiter , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Andy Gross , Srinivas Kandagatla , Mark Brown , "Michael S. Tsirkin" , Jason Wang , linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, NXP Linux Team , linux-arm-kernel@lists.infradead.org, linux-hyperv@vger.kernel.org, linux-pci@vger.kernel.org, linux-remoteproc@vger.kernel.org, linux-s390@vger.kernel.org, linux-arm-msm@vger.kernel.org, alsa-devel@alsa-project.org, linux-spi@vger.kernel.org, virtualization@lists.linux-foundation.org, Linus Torvalds Cc: Rasmus Villemoes , Krzysztof Kozlowski Subject: [PATCH v3 04/11] hv: Use driver_set_override() instead of open-coding Date: Sun, 27 Feb 2022 14:52:07 +0100 Message-Id: <20220227135214.145599-5-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220227135214.145599-1-krzysztof.kozlowski@canonical.com> References: <20220227135214.145599-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use a helper for seting driver_override to reduce amount of duplicated code. Make the driver_override field const char, because it is not modified by the core and it matches other subsystems. Signed-off-by: Krzysztof Kozlowski --- drivers/hv/vmbus_drv.c | 28 ++++------------------------ include/linux/hyperv.h | 7 ++++++- 2 files changed, 10 insertions(+), 25 deletions(-) diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c index 12a2b37e87f3..a0ff4139c3d2 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c @@ -575,31 +575,11 @@ static ssize_t driver_override_store(struct device *dev, const char *buf, size_t count) { struct hv_device *hv_dev = device_to_hv_device(dev); - char *driver_override, *old, *cp; - - /* We need to keep extra room for a newline */ - if (count >= (PAGE_SIZE - 1)) - return -EINVAL; - - driver_override = kstrndup(buf, count, GFP_KERNEL); - if (!driver_override) - return -ENOMEM; - - cp = strchr(driver_override, '\n'); - if (cp) - *cp = '\0'; - - device_lock(dev); - old = hv_dev->driver_override; - if (strlen(driver_override)) { - hv_dev->driver_override = driver_override; - } else { - kfree(driver_override); - hv_dev->driver_override = NULL; - } - device_unlock(dev); + int ret; - kfree(old); + ret = driver_set_override(dev, &hv_dev->driver_override, buf, count); + if (ret) + return ret; return count; } diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h index fe2e0179ed51..beea11874be2 100644 --- a/include/linux/hyperv.h +++ b/include/linux/hyperv.h @@ -1257,7 +1257,12 @@ struct hv_device { u16 device_id; struct device device; - char *driver_override; /* Driver name to force a match */ + /* + * Driver name to force a match. + * Do not set directly, because core frees it. + * Use driver_set_override() to set or clear it. + */ + const char *driver_override; struct vmbus_channel *channel; struct kset *channels_kset; -- 2.32.0