Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp2007222pxm; Sun, 27 Feb 2022 08:44:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJxw75bVDid3Lg7Lc8OWlQOhu2Vmy29rPg+pMVHnteLNbRqgDweqe4nNtr0ZmushaFdZRKA+ X-Received: by 2002:a05:6402:4245:b0:410:ee7d:8f0b with SMTP id g5-20020a056402424500b00410ee7d8f0bmr15851069edb.295.1645980273342; Sun, 27 Feb 2022 08:44:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645980273; cv=none; d=google.com; s=arc-20160816; b=TSBxpKCaj7UmJZpZqTcKmO3e/h/zEdeyIXPozXvwxENVoLU3FsZN2OTwjKXlW/WeIr B+kDXNEhf5KgR/7+waF9UHk/xQjo2ghKxK97Oiq6zkVZCW0lIrLGaw0ETD1sAR+wbPNJ C6w/45lsdZO8vtSn0WgP3KvKJ+jMIReb5tXpJXSHwXdyW57gfvEMNsYaRs6jPV2lSUrY 4puXOFPcNVTwiqUTdTlb8T7BvFQ6kT0Mf9xNSl7grLLJSKr2AkEiODJfXhs/jWqy7R0L GEwSu29YUx4NP0nb5Se4nDq6571keuSXonnkjaFD2biSPf3mY6OGaPgtr+DWILUTaao6 SbxQ== 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=npGNvoQmcQXzOf9MUvG7bOfkjnwx60Xk35PbEgCfPxw=; b=RT7Wf7K3NdTO/wZGVNFEi9fyVNeS0OOw8nALq5yHr/ZIWeVGcyf9wQaKui7f3916T5 pwVED1d+OeuMF79dcf57Pm3ivh2XG2i5tngaDTKEdAKwvQoDlcCrCeX810oJlIzD/1WP CskTYSVB2fjznHxfoDYYTFbYVLnr5DNyVQSIWzM96DAJlFjSWjFdxUhmdwx2T0XQ5iVP 8aJk6YoZWlEuaQP2VNSbnDZ3AiMqFk/KcOPbDcRpyutJZEbgeEzA8VjSF51U1XYED1eB tImuRpKy+alB0M0CqnafJos9yJyyFsFflqCpVNyvJZ3jnJeP+2jC80buuZRlL9baIZYt HwHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=TuSSqqLE; 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 g26-20020a50d0da000000b00412f4d8fa7fsi6310487edf.124.2022.02.27.08.44.11; Sun, 27 Feb 2022 08:44:33 -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=TuSSqqLE; 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 S231386AbiB0Nyj (ORCPT + 99 others); Sun, 27 Feb 2022 08:54:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231292AbiB0Ny2 (ORCPT ); Sun, 27 Feb 2022 08:54:28 -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 E4BE7193E9 for ; Sun, 27 Feb 2022 05:53:51 -0800 (PST) Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.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 E50A2407BE for ; Sun, 27 Feb 2022 13:53:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645970028; bh=npGNvoQmcQXzOf9MUvG7bOfkjnwx60Xk35PbEgCfPxw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TuSSqqLER80YcA1/RpVOJ2K5WL+/AG4UvX1GCjPhRt8igN7+egU3VdFqP01lBdTto bi/nxScJF30ylROyvEEDzmBsUOUKH6InN4ULr93fj2AJr3syOgPXbfaXz7M3/N9LIW hCMJbtjL2yP1tFFrmDIQ6Bi4VXsbkm6FTvIw0GqWZwMiQR4GVHTXM0Ve2Am0Xm3l1g 6opBlecxSjQoQZNWNbwBvD0FQY727Z2YQhARzYOUQVp8cpRLjYiV0QW/DN35YpzwmE GjrWXp3FtU8dOd1JGX00qfI4gOAsZqsOzTy9k27FjhYMmgfo+qL1uRfM4ltpZI6w58 WrGnFMGNOFueA== Received: by mail-ed1-f71.google.com with SMTP id y10-20020a056402358a00b00410deddea4cso4232363edc.16 for ; Sun, 27 Feb 2022 05:53:48 -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=npGNvoQmcQXzOf9MUvG7bOfkjnwx60Xk35PbEgCfPxw=; b=427dzMyVInPq2hVyZwG25BqoO8FV7AbzQdF7sESH8Hxhx/M48QXcKNhaM0TQexMA5/ W+AxRTyprl9wPk8wGiNbtMXXFhLvmB7d+q9lniuYcm5NoboYhppshxKbR2HBlqDCAf+Z Vt6TbqW53DfOns+Ly0wqotJ6SIDTWJNNpLm1IzvrFrTC3Mtbs3ca6LgFw2qv+fxlIAEE Xfcof1VicHIOdysxqRhibCzpeubMJkx+sv5xcTipLxBJZlm6hDVXUqdkDAM4nf3fUhqk BKWX+T4v1BSs+nB6JoMRliYboHvxiyETo4NwIEBd5lqFXi7R2vrPzCrUrjzhloNQdxP2 iX/w== X-Gm-Message-State: AOAM530v/9IKwSpnJ/cD2z0QCm1QWvNSvNiiVxeegrkB7xopzFE2+gMo PSCRZb38Wdevnm2dQRB6tT/4tRIKJAPPMpiBpfrBHB+ATwgYp3yHb4/ne1iRvAdpst94Zf+ZTqj psu9Bjzu9bkNZ0TQrAC/iwgHBUYnlNmkAfI7E4rb8nQ== X-Received: by 2002:aa7:d49a:0:b0:410:875c:e21b with SMTP id b26-20020aa7d49a000000b00410875ce21bmr15261473edr.357.1645970017413; Sun, 27 Feb 2022 05:53:37 -0800 (PST) X-Received: by 2002:aa7:d49a:0:b0:410:875c:e21b with SMTP id b26-20020aa7d49a000000b00410875ce21bmr15261460edr.357.1645970017251; Sun, 27 Feb 2022 05:53: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 w11-20020a056402128b00b00412ec3f5f74sm4600760edv.62.2022.02.27.05.53.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Feb 2022 05:53: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 08/11] vdpa: Use helper for safer setting of driver_override Date: Sun, 27 Feb 2022 14:53:26 +0100 Message-Id: <20220227135329.145862-2-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. Signed-off-by: Krzysztof Kozlowski --- drivers/vdpa/vdpa.c | 29 ++++------------------------- include/linux/vdpa.h | 4 +++- 2 files changed, 7 insertions(+), 26 deletions(-) diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c index 9846c9de4bfa..2d924a89ce28 100644 --- a/drivers/vdpa/vdpa.c +++ b/drivers/vdpa/vdpa.c @@ -77,32 +77,11 @@ static ssize_t driver_override_store(struct device *dev, const char *buf, size_t count) { struct vdpa_device *vdev = dev_to_vdpa(dev); - const char *driver_override, *old; - char *cp; + int ret; - /* 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 = vdev->driver_override; - if (strlen(driver_override)) { - vdev->driver_override = driver_override; - } else { - kfree(driver_override); - vdev->driver_override = NULL; - } - device_unlock(dev); - - kfree(old); + ret = driver_set_override(dev, &vdev->driver_override, buf, count); + if (ret) + return ret; return count; } diff --git a/include/linux/vdpa.h b/include/linux/vdpa.h index 2de442ececae..89ec4e4d4cdc 100644 --- a/include/linux/vdpa.h +++ b/include/linux/vdpa.h @@ -64,7 +64,9 @@ struct vdpa_mgmt_dev; * struct vdpa_device - representation of a vDPA device * @dev: underlying device * @dma_dev: the actual device that is performing DMA - * @driver_override: driver name to force a match + * @driver_override: driver name to force a match; do not set directly, + * because core frees it; use driver_set_override() to + * set or clear it. * @config: the configuration ops for this device. * @cf_mutex: Protects get and set access to configuration layout. * @index: device index -- 2.32.0