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: 12782767 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E5558C433FE for ; Wed, 16 Mar 2022 15:07:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356937AbiCPPIM (ORCPT ); Wed, 16 Mar 2022 11:08:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352776AbiCPPIL (ORCPT ); Wed, 16 Mar 2022 11:08:11 -0400 Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA4DA66AEE for ; Wed, 16 Mar 2022 08:06:48 -0700 (PDT) Received: from mail-lf1-f70.google.com (mail-lf1-f70.google.com [209.85.167.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 BA7763F7DE for ; Wed, 16 Mar 2022 15:06:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1647443207; bh=qe4dhnprNWM6uzn5SGQYSUaT3EAa0OIFZFVGuX4NqAE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=G3M8epcWeWLrSaltefWsa1g5r+hNaM+3m5oxYwSF4iOsbIJmU0RWFEi/7NO3JBdVv w3OcSgtPjuPGDT3gJvA+enz39tMCQ6hFcv8tH8dv4SUjX6mejGfOp2C2bOiJcmn7PV qt7Bsx9xW/WcVnfHN/x3z9Jd9dPcavX1xTGPMkFyCKsxXXXQdWhPnawoOGN8YP6cHY neWrNpse1h2e7JxerQopLpRqxiFmnzaydxW0QpeDYNyCB8TiDY/O+reNbrNtmx1HhX R9wV/94Np6NsLzKlc+/O7eNhs56F34gHOoaYfUWmquPUkb45vJe5m6GWKT/vYrmZkC Az3+wjvEne7CQ== Received: by mail-lf1-f70.google.com with SMTP id y18-20020a197512000000b0044864aef6edso845426lfe.7 for ; Wed, 16 Mar 2022 08:06:47 -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=KE+UkroJbjRsBk8Rbn6h0mAQ2dV+/4GUIaJnvl41+drg2Fpc3k7b05RX9Xsx/lpbjj M++yMcr5TfAakVF+hGAMCBm3Mi7rdutaG/9i6n4jVspGXzzOhB8UpDkjEcFrUIOsVZqr eEKV8+I2VbpWWduFxT7sEwZlkv5cErccYAPWCbEYcceeBVnkID5DXld/wHjQ/FbmeW7w Z+CLNPkLQOaIHEQvR97Za35UeBFno5LgZcXaM7P9IdA9gfjEoEQVhnRqcTE64CRzNFgG N91o1uz12k5QW+S3sQlk4Ps/1lcRQxXx+PbbAXMLc93H8mK+YDBYgV/wc3DCd5By3AA3 GBdw== X-Gm-Message-State: AOAM533Gejq4eiwThEQmfaEkZL8mMqn/j6m81PUWPUkbW+0rtXvsMYQl vYDzaqYWDoHc+0mDQDsyB9C9ZZSWX7qtQb9j3Ws15XYJOviITpNx8p1HTRKxgBwvnfbRov+MzoG 6Ea+E7+oBiGtdzgJjeE1dOChSC4Aa35YHFPpSgQ== X-Received: by 2002:adf:f48d:0:b0:1ed:e2d7:d5e0 with SMTP id l13-20020adff48d000000b001ede2d7d5e0mr339361wro.252.1647443196964; 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 Precedence: bulk List-ID: X-Mailing-List: linux-pci@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 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;