Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp3510467pxb; Mon, 4 Apr 2022 19:19:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwmDcBu/8tA9K2zeySEG9ijMMiRwgrxnLXcxWUURiYjtmYIykvLukKJZ0MXQy8WqvFAzslq X-Received: by 2002:a17:902:6acc:b0:149:8f60:a526 with SMTP id i12-20020a1709026acc00b001498f60a526mr1122846plt.25.1649125186078; Mon, 04 Apr 2022 19:19:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649125186; cv=none; d=google.com; s=arc-20160816; b=Ynwj98NNWh5nVs67ApYHozzvMhpnHtsR5xWHTZ9DXRwg0+9/tIPQDx5aTKuEtTai0s ZXpt3Zc/ycQDYtHQ4vhWXoURVfmUMpD0yJXwhXJ7OsP2gfJ/QB7ErsZCd/80/I90PHsp IJ4lnTu33oA6WfIRBMa2g31jwTRZSFMo2cEtXX/4qdwo9ylDBHKKTBuJPFlxKheFVA1B 2lCNBGCrVwSpHDCwwj8F6jsY/mK+K+HgDrphZelmldMXOIFdQUenul+zPpgCV8sFWhxG Hm7Q3i6O7tN6HC8ke/Fn+gbhOubDxY9HIDoulMKKG71te5ki3skb51ucXvLInJ5NfVRA 8dTQ== 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=zzWwD5DTusKMDFInVhaL2Q4xRdExZxvYFPCG18bh4ek=; b=uJSsM7JPXwrNWbt+WWJU0LZ9AZ0B7BS0pwvhN59iBfch5g8OoAZHmNcknDvPIEF0O9 TMG33KmJBbkXAFl5F6Jejt1FkLVYUQBk9PEq4JALDi1+fdSQX1jeNCSj32H+K2hKw5Gb eR83pl6Q0M0HJ/O3hlEsWnoj4/qA7Y3KXr5jyZwpmjbUkGLgp5S/RjjO6XykqHj+y6Sc /I6IBPE9OVn5w6G4Ye0mXWTA9GW1QVD3uSI7J9duyMmYkFuiO+FJIm6FeeeXjnXcBNN8 MyVYb8LzCudWKWS6uhOmhgXtK9LVXnpjYoWAgcEAoj/DkOyziPJRJiDjjsHawklb2N4o qFSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pXYMNOml; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id w4-20020a170902904400b00156a18597easi4870493plz.452.2022.04.04.19.19.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Apr 2022 19:19:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pXYMNOml; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E512329E4C7; Mon, 4 Apr 2022 17:41:39 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1359846AbiDCSkx (ORCPT + 99 others); Sun, 3 Apr 2022 14:40:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1359865AbiDCSkg (ORCPT ); Sun, 3 Apr 2022 14:40:36 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2CC2F49 for ; Sun, 3 Apr 2022 11:38:27 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id w4so11356395wrg.12 for ; Sun, 03 Apr 2022 11:38:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zzWwD5DTusKMDFInVhaL2Q4xRdExZxvYFPCG18bh4ek=; b=pXYMNOmljPv1o7EtR7qMU+QLwEsAmQfNWT5C7EmlEUDcHVev7zWnMU1wDa9z7YEgVr rv0cYpCdaXctn8jk2MP5e4W1nl3/MgmVSsuslHdKngz7Y2TCVvjylcvkZCnNBzHKyYcX +/u8q126tBEwg18F5VoemEeFiKO4rq5TGWe08IH/s5KCaRO+VXAhayl5tc7ilaKgTnJp TrY3763NH4xwR9tqEBgWot9nt3fqO2ul1MxhAxPiERAkpXltSMCWQLcSZBAE8CFVcaDf c4xGNBoBMLmHJcFh9EysU4fsVW5rn1i6PHCmp5CW678fSPgzHSd8EgNQ8ut2ZJ4V+Pff z/5Q== 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=zzWwD5DTusKMDFInVhaL2Q4xRdExZxvYFPCG18bh4ek=; b=uRC+KeYyp+ccTwmyTegz/gooS/xdoJs2qK8/RLVgNkKXiCiYIrtalv+yJnPYsQ3im3 H+MTl9phdaZPxMz/ndQnYw6GLcpSuGO6Wk4wf1wndxuesjkjDgUGbWx6ApnlMWM0FdqC fs3BKsJgGpgzO9J7CjdldEzyY2kvahpG1xfcLErvf/XyPXBUoYKJZE6g6/TItvcxf6an rgWZAe/Ujhv0C16TVaWGdRGzQ8azeSCksvYky6dtNlxINInfGZUVxonnqCp6ckZUdQMc CJuLF6HVp1uFDVWtgvPTUMyrFQd8YqO/GGc4v7w0SWB+v6SHcIO8kruJmgSl1hseUL3T 2krg== X-Gm-Message-State: AOAM531wwr0CwBGSnMU+XN+vxkbYlNy5pzygjV+1jD+Hcr9HKUpiCZ2o R1oC3+ZnlPO6kOJFKfGHb65cPA== X-Received: by 2002:adf:816e:0:b0:1e4:ad2b:cb24 with SMTP id 101-20020adf816e000000b001e4ad2bcb24mr14679431wrm.521.1649011105785; Sun, 03 Apr 2022 11:38:25 -0700 (PDT) Received: from localhost.localdomain (xdsl-188-155-201-27.adslplus.ch. [188.155.201.27]) by smtp.gmail.com with ESMTPSA id l28-20020a05600c1d1c00b0038e72a95ec4sm593851wms.13.2022.04.03.11.38.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Apr 2022 11:38:25 -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 , Mark Brown Subject: [PATCH v6 07/12] spi: Use helper for safer setting of driver_override Date: Sun, 3 Apr 2022 20:37:53 +0200 Message-Id: <20220403183758.192236-8-krzysztof.kozlowski@linaro.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220403183758.192236-1-krzysztof.kozlowski@linaro.org> References: <20220403183758.192236-1-krzysztof.kozlowski@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 to set driver_override to the 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 c4dd1200fe99..1b31cae35dd8 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 -- 2.32.0