From patchwork Wed Feb 23 19:14:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 12757403 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 2BF23C433EF for ; Wed, 23 Feb 2022 19:15:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240128AbiBWTQJ (ORCPT ); Wed, 23 Feb 2022 14:16:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244271AbiBWTQF (ORCPT ); Wed, 23 Feb 2022 14:16:05 -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 1AB47403EE for ; Wed, 23 Feb 2022 11:15:37 -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 C6A243F1B6 for ; Wed, 23 Feb 2022 19:15:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645643735; bh=H2keAgAmU9ZqqGFkafNbZlkvfevlWycDJlQlht8xanA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=D9cwn5BL9MJVKNDemIQCrFaICpDe78PK6gdsb+A9hCiVzMCyGHUdgLj0deXkaB2UF 0FxQrL8efj7296DUz4nlCSKXDyEbXgigCxMrLXvvZWOCQLxbATRYszC5dD0BeqfkI+ QI4Sh5b8B/0uV5AHMMWEa093+qo57eXd/5Hhy5xof/yX2En854YJsMERCcsdgDraZC kzMdnKdJumVA1mq1076sgJrnBpd6e+6fk0ZKK2ndhDbFnQtLeCzMM2CnLbATXXRz0K 0SkyHI/FLIxXDtfprEo8+fn54FMvA7w3FCw87+jJ88o3MnntjALE83uHpz2aVYa+7a qezG5wWcBlHhA== Received: by mail-ed1-f72.google.com with SMTP id r11-20020a508d8b000000b00410a4fa4768so13937462edh.9 for ; Wed, 23 Feb 2022 11:15:35 -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=H2keAgAmU9ZqqGFkafNbZlkvfevlWycDJlQlht8xanA=; b=c+/nMNcZTXo/fOhpSK2p8xS00cKYYsigQpJCuz8ZseBm9vTu1Ml3bJqNuFPD+GeQz+ kqcGmTSZNaZqK3fhCLDY0bVH6XZqQMl9U+uo1P6B+rbtorELkTXBd9XEmu+KxydQNiga /X4icPz3HUFggKv9QjAR1NOuI9FdF9T8J5fMBkT/r7GPt4ELLTikeUodH4AQt46+bMit PDqurg/uHBS0pDDgkR/cRQea7IZUFZbJMVKX7iWFHNhR8vMnfN4EgmozxV8tnCORXY1G v5YTz8z0KEP9Qf/PCZVuYY5PfZ5p1c/5ZNbnkrDgpz+DRNYJ96EUt1th+S1rABmB9470 cXIQ== X-Gm-Message-State: AOAM530zq+OWriQ9+8GafVkX1Y5+iCY8mjA41VCis2Bd8B3/oHIBd1tB ZO5L/32qhH3ief0cYoEvSOuBds6F0HWUuc1zgrspFwIPPjAAucHBgKUz91c+pjFE9pMba2PuKtA uE1JxkgDjAeHI/yZwrzAFq2UAg0S8+D35JtjOLw== X-Received: by 2002:a17:906:684a:b0:6ce:c1b4:b503 with SMTP id a10-20020a170906684a00b006cec1b4b503mr894495ejs.355.1645643725344; Wed, 23 Feb 2022 11:15:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJwpQByhmcToLCr1i/g+5dfeJyrnQroTWuW6ciExOrKYOzQiErT2Fu468xjrk+1eigQXSikm5Q== X-Received: by 2002:a17:906:684a:b0:6ce:c1b4:b503 with SMTP id a10-20020a170906684a00b006cec1b4b503mr894476ejs.355.1645643725160; Wed, 23 Feb 2022 11:15:25 -0800 (PST) Received: from localhost.localdomain (xdsl-188-155-181-108.adslplus.ch. [188.155.181.108]) by smtp.gmail.com with ESMTPSA id b3sm208368ejl.67.2022.02.23.11.15.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Feb 2022 11:15:24 -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 v2 08/11] vdpa: use helper for safer setting of driver_override Date: Wed, 23 Feb 2022 20:14:38 +0100 Message-Id: <20220223191441.348109-2-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220223191310.347669-1-krzysztof.kozlowski@canonical.com> References: <20220223191310.347669-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-clk@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 | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c index 9846c9de4bfa..76ce2dcae7cb 100644 --- a/drivers/vdpa/vdpa.c +++ b/drivers/vdpa/vdpa.c @@ -77,32 +77,15 @@ 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); + if (ret) + return ret; return count; }