Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp1998733pxm; Sun, 27 Feb 2022 08:30:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJxFEryAacUKvL53RrfUz0G/HFTV/SH6gbT0G2FQTYbEV2MdzZaekDg4PtBYbsfJxzp9gmmS X-Received: by 2002:a17:903:120c:b0:14f:3f4a:f832 with SMTP id l12-20020a170903120c00b0014f3f4af832mr16912106plh.157.1645979417461; Sun, 27 Feb 2022 08:30:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645979417; cv=none; d=google.com; s=arc-20160816; b=bTqRT1UcY9aIJy/xWleN9e4w66RlE6oeyDUlMMrhfNxwFdsEX6gQcZGgLceXurqfLw A3OTxaqrkbefcwfNlX5F2EXIx+Am4i8MNSa7yRtGzjXQa/XCPxC4QPM8hiKzB7Sru60B amhZRQM7Wz6Xp9OQ/Nh1fGXpPIsx1DvOMPEX/KyK8MK+b1maDx6f7Fzks0WSYr6W7yqt OAFuYHJ7rO3NWbKS51O9PiRdVqBDgmWwX+yRKMsbiqtZhv6S8kiYRia8PifjJfcu5Yjy zG1wzVpuBg1A5oomYYoMUIiJpzwurSz7Q0FQtfJFv02RFKA3T+viW4SUj5ade+1GjJxr U00g== 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=qpFiz05rVbRuRAHN9hg8SmLpkD4Xh7SLbxYijfSgBwA=; b=sWm1glSCTgYDqs0m2H6e8Tx0ZT0Ezfkf6BGgz+fRaN6Ux5eUOQxSBAz0kZFWAbNXLB DQS1qInad+F9xAdoVQ1QLoHQQNYGu7XKaZ6kfc8VWzs3Ffjzwec8Ef14KDACjUokAXut 3HJg2tcoFzE1Ak479UAxyPKrdoVUC5HXhulLBbLGCtCn6+RBz27coGFX4Myb2DENody3 Ml+pNg5egTM76uhLu6SgdN4dnIj2vUnoaI5l4sWEZyzGscBjR3TIHLjkjNeE+nRJIBPt S5Qq9WCB1WOLAFZR1CNk96Q5Ur/mF8XD5LJ2O8ysSaN/YQ5zy8donBmqyLMiGdqxXepO vvVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=gb15HBHg; 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 g6-20020a170902868600b0014ffa5402c1si6846052plo.450.2022.02.27.08.30.01; Sun, 27 Feb 2022 08:30:17 -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=gb15HBHg; 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 S231208AbiB0Ny2 (ORCPT + 99 others); Sun, 27 Feb 2022 08:54:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231328AbiB0NyZ (ORCPT ); Sun, 27 Feb 2022 08:54:25 -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 AE98C13EB7 for ; Sun, 27 Feb 2022 05:53:48 -0800 (PST) Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.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-0.canonical.com (Postfix) with ESMTPS id 7A66540017 for ; Sun, 27 Feb 2022 13:53:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645970026; bh=qpFiz05rVbRuRAHN9hg8SmLpkD4Xh7SLbxYijfSgBwA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=gb15HBHgoa4/ayNDCdpdmkOHg8MUudIN5aCRt8kMUNQuhCGe0tXAgYg2BZ4Wgdm4M qBUCRTaxMvAfdfPwR6t21rNP810akTda5OJl3rrG66W94L60NkwzgdrO6LGHixEoC0 mtL8XKljlgqmn9PDfs1pNLGg+G/hU/hx7RIGz76qfGuSLMDgc+Fiuq2YGOWcsz2Dtw ya2MFy+fIGgozBO4Q0HH8HHasTR4LIhfR22633fEJ9H+OXUrdtw93RQUvyRwzNHkJa i643G2PdQvtrnsoKvkikJGsKnEQEJEQhO49xmg958/SU430tuDIDLcYxFaV/y7CnAl LVOJyjKpyymvA== Received: by mail-ed1-f69.google.com with SMTP id l3-20020a50cbc3000000b0041083c11173so4254569edi.4 for ; Sun, 27 Feb 2022 05:53:46 -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=qpFiz05rVbRuRAHN9hg8SmLpkD4Xh7SLbxYijfSgBwA=; b=DwMEhW9rtKYIelCXMZHlJXq7kwiUHWUk1lwS1D7CQZvIzQRqlldlM7YcEcgx7oss4X nm59FjWMm6inO0q6RsNWNuaz4jKEAV8UPMPxBErn4KDDEry7drJD4iJ1rZEvDn2tlgaA O393lgfCPw8S3Vm+0vTVRzhIJrpb1qDWTppFfXdqNSHWAlpy1NCAzAjTJzH6Ap1TXFCL JLCT+8pEBsqkVNUTiWC3Y+Y464ftvteTrTjWX/f8HBbH8M9l8Nf183q170Tmq59xsiFt eFQC3AV03M/AwW6hj8Pl7KHLJ0JcOVhPEMAtoXb6BVYsogOCTt6AJAs0zYTO/chW9bzN Bjiw== X-Gm-Message-State: AOAM530A8r7rfT7hHJ982R0ZdfqVQeaSRvugoSjiLcXBd9kGtCHYpRVT M4VpMBfAKo2DMCJKOKuVB4V7XQQN+Ul3kRxFwVLFAGnx7quuUvuJYr1n1VsHSaAjj0aTuVF68L/ VMgspcEsumLKsRwWVarDJg5w2O5iHicg3mRhlZjzusA== X-Received: by 2002:aa7:d98a:0:b0:410:b844:7889 with SMTP id u10-20020aa7d98a000000b00410b8447889mr15100900eds.109.1645970015740; Sun, 27 Feb 2022 05:53:35 -0800 (PST) X-Received: by 2002:aa7:d98a:0:b0:410:b844:7889 with SMTP id u10-20020aa7d98a000000b00410b8447889mr15100871eds.109.1645970015533; Sun, 27 Feb 2022 05:53:35 -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.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Feb 2022 05:53:34 -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 07/11] spi: Use helper for safer setting of driver_override Date: Sun, 27 Feb 2022 14:53:25 +0100 Message-Id: <20220227135329.145862-1-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/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 4599b121d744..9d0b11017741 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -72,29 +72,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 7ab3fed7b804..f99bbb20dd4b 100644 --- a/include/linux/spi/spi.h +++ b/include/linux/spi/spi.h @@ -136,6 +136,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_gpio: LEGACY: gpio number of the chipselect line (optional, -ENOENT when * not using a GPIO line) use cs_gpiod in new drivers by opting in on * the spi_master. -- 2.32.0