Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp3502671pxb; Mon, 4 Apr 2022 19:03:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyt/AvUsH38JZTBHKep9+JNBRCLCoBipawKvQHp6gqN4FMMsVO0z8GaPlIErWcEwyO3yu0g X-Received: by 2002:aa7:888b:0:b0:4fb:10e1:8983 with SMTP id z11-20020aa7888b000000b004fb10e18983mr1125568pfe.62.1649124216673; Mon, 04 Apr 2022 19:03:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649124216; cv=none; d=google.com; s=arc-20160816; b=pOOT9s1Q0FNO5/Xyz7t7XDPp4MbGoUqDo06OR+zeA6HWmehn52h4P77DvqT5oyQkv0 NiYrcLgA7HaWtaGqi8WtASEhDsebXs8sjshloTMQk5A5cgv+Qexm5KUEorMRLMNVotvk Pw6ht27epB1iNNc4NqA1ityDTJYh/2D021BVSEvQ1mUnsVKphnGD72n9kPBBI/vQv/QM oEDvhpHvjKcZgssqMxyXRdfYcT9uLyr7EzDe+/lB6naQ36n80uaaIQU8Wl156P4GAMar rQkBr0AdLieJdmkQUn3/PP5t86oPA9073drIj7AV3P+EkihANk8sR3gaNoUqOYZcJSiU HURg== 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=Keg7xeXtq8amo+bPOPiY0urtb62UU+nYY2PydP0Pktc=; b=aCbEJ7yvp4FVgxrpdsdGPB7PkWKzwEZbj++nDwz/BJUsdMwkrP97SmAHVFlWdKryEr xs248GTKwscso+6LonJcagIrW7O2eCeU3Uqma75PB9JjGEttprEvWQa/zWvBn7kZKScW Z+av7sAA6bBRgS3u1jPjsfqf9kXGlhPlTxiWRyhwl24Y4uO7DOvQhM/mXbAmGUjyOhQB 4kp+r8KWDm4LwYoJIticjl6z97wVRCgNzbPEZeFEiBtRQpcOMSRBf2NiFDtADPvYs0H/ eeaATm3S/uVXf+bZT7D/ZsS3f++WJbMQZnN66W2TaWH8j1W9Lobq6NVu6u80UJCnkioY UX2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=oMDcsOp8; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id f68-20020a636a47000000b003816043ee4esi11487643pgc.67.2022.04.04.19.03.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Apr 2022 19:03:36 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=oMDcsOp8; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B5EFA204AAF; Mon, 4 Apr 2022 17:26:48 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1359816AbiDCSkc (ORCPT + 99 others); Sun, 3 Apr 2022 14:40:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1359821AbiDCSkP (ORCPT ); Sun, 3 Apr 2022 14:40:15 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF76139837 for ; Sun, 3 Apr 2022 11:38:20 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id h4so11347158wrc.13 for ; Sun, 03 Apr 2022 11:38:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Keg7xeXtq8amo+bPOPiY0urtb62UU+nYY2PydP0Pktc=; b=oMDcsOp89xo7WCGlZaySjQ/SL9h0nzbICnZPF/l1L4/usr5Ql0XDHyOs8k4ehjMSBS wNLyu4xPPW/8LHM2Uedk1hGpH5fictG31y/jaW9+iVnJSqBp/jUgPgpae1FA5DICWkPl YRAMESUeV51a7RHc95N5iNDkYhYQTFttdVTgxIhYSFABzCUtxnFZt5jqPxICNNpdDyHs POzj/+QSYOjZLCMMMqS5ghku+l1wfklLbj2jy/IljcHTXhZXw1iJrrLT+I46o5bsitlo KU065Iswr+ZwwCsrhwgctLc+GzCy0ejsf5qoEOvNZuD0oCpZAaZA1eMhHX76M2B3fl79 o24Q== 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=Keg7xeXtq8amo+bPOPiY0urtb62UU+nYY2PydP0Pktc=; b=msSTWys1XLnn7nrnk7L39n7kotfiR4VgKx/SoeU/HMA2/R48ztOA4wySYxZdfKLJCO uWatf4jL04vxYoHw5eHymzvMZKO7+38NBiI8gyuunzdZ0jrYRfX1AeZO2MKMx32UK6ds wY3tpfsmwCvqtYMcn43VPosvRBmRbJMJCIhBrUzjcXB1cokDMnOYmaZpr2H99bBvkei8 XtfBK89ORFsxyRdkzXPPNX0sh+ZYgXmCR8jyjZ4X80lYWCKxAvoAv1zAvyuW/FRZ4EWE vDKlNCg2G+t/a6fuemm5Md695njet/8E5Fy3u6SVmAzpvOcg5gtWu/reAo/YBlHBf0wY QjKQ== X-Gm-Message-State: AOAM530jkZXI5OfUQ8u2KJNy0kVT6MZ6kdCXY3vZHaYJBIivO6EeIMcf c0hFyhgNBaN3Kij+m2yOxKhMog== X-Received: by 2002:a5d:55c7:0:b0:204:5ff7:74e2 with SMTP id i7-20020a5d55c7000000b002045ff774e2mr14445001wrw.50.1649011099197; Sun, 03 Apr 2022 11:38:19 -0700 (PDT) Received: from localhost.localdomain (xdsl-188-155-201-27.adslplus.ch. [188.155.201.27]) by smtp.gmail.com with ESMTPSA id l28-20020a05600c1d1c00b0038e72a95ec4sm593851wms.13.2022.04.03.11.38.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Apr 2022 11:38:18 -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 v6 04/12] hv: Use driver_set_override() instead of open-coding Date: Sun, 3 Apr 2022 20:37:50 +0200 Message-Id: <20220403183758.192236-5-krzysztof.kozlowski@linaro.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220403183758.192236-1-krzysztof.kozlowski@linaro.org> References: <20220403183758.192236-1-krzysztof.kozlowski@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 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 14de17087864..607e40aba18e 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; -- 2.32.0