From patchwork Sat Mar 12 13:28:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 550789 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 33FA4C433F5 for ; Sat, 12 Mar 2022 13:29:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231952AbiCLNax (ORCPT ); Sat, 12 Mar 2022 08:30:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231980AbiCLNat (ORCPT ); Sat, 12 Mar 2022 08:30:49 -0500 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 E0576208C1F for ; Sat, 12 Mar 2022 05:29:38 -0800 (PST) Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (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 AA06C3F4BE for ; Sat, 12 Mar 2022 13:29:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1647091777; bh=bxeIyEILguhVZg7q4olJhqVfW5jjl8OfwGMF3r7ek6k=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=sapQgqq3Ux5GGzb3neZCo8S4VGHxuD8MJ9TRxmdZnyWgdeENxzj42vqzGn6RjPeLs /Y7ZEJiub4VBYtR1FZu4ZndlRSQvkPnFQdrTx1BxSeYU8xicjlKKaExd0sFpRtHYyX iSL870hvS4RdtLSHn/LIRxdEv5RhITAVAPoxHo0/OvB6tiBFG4uRGKRWI5lfN7VF5f dKTFVTQE1KpQSBmCjKKdiuwbHJwjQh3pJ36QBpxx5VVr1qIs8TPZw33cJ4CyOFiYP/ UVCa2/N5Vs2vwFzLpTRyFDvSUpHgUB5n5G48f6avvcaT9izfqalDJO6aU8fxhMuHK7 nHVk3zW9Id8Bg== Received: by mail-wm1-f69.google.com with SMTP id l13-20020a7bcf0d000000b0038982c6bf8fso4380090wmg.7 for ; Sat, 12 Mar 2022 05:29:37 -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=bxeIyEILguhVZg7q4olJhqVfW5jjl8OfwGMF3r7ek6k=; b=Zlxwx2Kd7sjSvQJWVDgSUmklvLehdfPIB7VPCvYKX6/cxBYQ+06t/MCcr4BBv7NR4T 6smSNW/gwzf8lkSnyjWZNOJ8a+zD3exY2azgiztcUxMMLPsc0+QHgDUFRs7jbD4jPxGK eoo9ck2nfF6josmUsmZS+22uA2drW+orzAVZ14Vi1OyqCrCIcu0nZ19sYJAFBS69ja6H DnL0LxZOyqvQozZkalup5TvGDf0weJwlPQBi8ZSr7arHI6qorxP+/hviu4RkpaMESKEw rL0GAAueOrIA/tXoStJ0hM5tBKFLwv5lXFOYzOm5HoXNdJKPLIAfH7940PJFTdhK+tiG OUqA== X-Gm-Message-State: AOAM532g99xw5i24ZpqRjlrRUDHuGybbBa2Dintsxsu65SS4pA51fMc8 uNlBAKlkaQYvn284JNzywXDmFHAHY0ZUqToWMs3JyzerW/OXI6dAjEvOtc7sOUGG0i9Z9e837iA ImAIoSh7zvd5zTfJYcOHhep+peGcLxo2eUJblTfR6HsU= X-Received: by 2002:a7b:c250:0:b0:389:7fe5:d34c with SMTP id b16-20020a7bc250000000b003897fe5d34cmr19242467wmj.83.1647091766881; Sat, 12 Mar 2022 05:29:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJzz5i5+OuGUNvCz/VZC21UZB6s3lmwCMCHTfnN0kBuu25n6H5eL3kzENek+qi2xjBkf4IC46g== X-Received: by 2002:a7b:c250:0:b0:389:7fe5:d34c with SMTP id b16-20020a7bc250000000b003897fe5d34cmr19242450wmj.83.1647091766634; Sat, 12 Mar 2022 05:29:26 -0800 (PST) Received: from localhost.localdomain (xdsl-188-155-174-239.adslplus.ch. [188.155.174.239]) by smtp.gmail.com with ESMTPSA id p22-20020a1c5456000000b00389e7e62800sm5751550wmi.8.2022.03.12.05.29.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Mar 2022 05:29:25 -0800 (PST) From: Krzysztof Kozlowski To: Greg Kroah-Hartman , "Rafael J. Wysocki" Cc: 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 , Rasmus Villemoes , Krzysztof Kozlowski Subject: [PATCH v4 07/11] spi: Use helper for safer setting of driver_override Date: Sat, 12 Mar 2022 14:28:52 +0100 Message-Id: <20220312132856.65163-8-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220312132856.65163-1-krzysztof.kozlowski@canonical.com> References: <20220312132856.65163-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Use a helper to set driver_override to reduce amount of duplicated code. Signed-off-by: Krzysztof Kozlowski Reviewed-by: Mark Brown --- drivers/spi/spi.c | 26 ++++---------------------- include/linux/spi/spi.h | 2 ++ 2 files changed, 6 insertions(+), 22 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 6937cf2d59e0..34f311224c47 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -71,29 +71,11 @@ static ssize_t driver_override_store(struct device *dev, const char *buf, size_t count) { struct spi_device *spi = to_spi_device(dev); - const char *end = memchr(buf, '\n', count); - const size_t len = end ? end - buf : count; - const char *driver_override, *old; - - /* We need to keep extra room for a newline when displaying value */ - if (len >= (PAGE_SIZE - 1)) - return -EINVAL; - - driver_override = kstrndup(buf, len, GFP_KERNEL); - if (!driver_override) - return -ENOMEM; + int ret; - device_lock(dev); - old = spi->driver_override; - if (len) { - spi->driver_override = driver_override; - } else { - /* Empty string, disable driver override */ - spi->driver_override = NULL; - kfree(driver_override); - } - device_unlock(dev); - kfree(old); + ret = driver_set_override(dev, &spi->driver_override, buf, count); + if (ret) + return ret; return count; } diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h index 5f8c063ddff4..f0177f9b6e13 100644 --- a/include/linux/spi/spi.h +++ b/include/linux/spi/spi.h @@ -138,6 +138,8 @@ extern int spi_delay_exec(struct spi_delay *_delay, struct spi_transfer *xfer); * for driver coldplugging, and in uevents used for hotplugging * @driver_override: If the name of a driver is written to this attribute, then * the device will bind to the named driver and only the named driver. + * Do not set directly, because core frees it; use driver_set_override() to + * set or clear it. * @cs_gpiod: gpio descriptor of the chipselect line (optional, NULL when * not using a GPIO line) * @word_delay: delay to be inserted between consecutive