From patchwork Tue Apr 19 11:34:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 565329 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 alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3C544C433EF for ; Tue, 19 Apr 2022 12:00:00 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 7DA9C18D4; Tue, 19 Apr 2022 13:59:08 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 7DA9C18D4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1650369598; bh=yfV5Ce//hrFx28s4Boowp0TOz7or7LKNd0o/pVqSAfs=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=uHtYl9adOepFSfNxl9L3GTQ81XdcWvxHlaXQsaEJY7s/tMLPJiSCQBBuTCbna6+Ae 50FjT1KR5l2cQA2YfxrQqqtlc54hwdu6khZsjaAPXuu8/miufyHpiFLs2xeJmz53OF OW2C9EEuZmJdkbu5TDv/r/TIRzLGa/DMrNwMQBVs= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 153BFF805C8; Tue, 19 Apr 2022 13:52:39 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id E4FB6F804A9; Tue, 19 Apr 2022 13:35:07 +0200 (CEST) Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id C1241F802E3 for ; Tue, 19 Apr 2022 13:34:59 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz C1241F802E3 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="hKtmLd1k" Received: by mail-ej1-x62e.google.com with SMTP id g13so4533113ejb.4 for ; Tue, 19 Apr 2022 04:34:59 -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=TqdyAx2hKeSTzZvT1XZ7Yq5gael+ofTQxaoTtQ8gQMM=; b=hKtmLd1kRNuBSXB4Y7mNdjpReUDXku+irhd3zFAz4Ubd8SwaqokXDkdCB7GIdLbryC L5stcsj3hpBSraDpJqv7BG2O3Juzg/3EfXdjMZx8tIRDDKWLJOmn5wykqM0KVif5PYqp +fbosiRSyUUjDpvOJI0DDaXlJMdCEf054dEGpQoaLz8IrPX9Zzhk7Sdkp8zNYMq5cX+Z 8lspMfQWfQIiZdDfVA4rWW44DdE2e4HYXE6T/UJCOpqm1oRwWHdeKhpVttS9B/fTWkB5 pqEJAMzXa2pi405ICk55ytJCWuteAq9boASuNBt2ImF9uXS9tCWG8SQsjL+Xex8Ef3Lx WY1g== 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=TqdyAx2hKeSTzZvT1XZ7Yq5gael+ofTQxaoTtQ8gQMM=; b=niXcQXgFTDV/zHqLrVXFASpEJVGCIeHtdk7IF9Xj6wIgLw9+L2tosZB/O7feAOggpl fVtQJm6a+S1bOD3bGxPSLLeRwa9IKBSAmC07qEBQ+PnDScNVTfn8RnR5UcI3X/sByRJj voJB6k0XNqohhPhtYLcjuofhAPw/YxnbscJVZH/SRwxn2TNLSTnct+iAJvxpssiTv3VI /oqM0PiE7MKX5liHe9dUetsUaTaH4WRt5FAwh3lf7yRGuaTRZpPD31DH9ldkTqPJx336 nRwXQiGoLapW3fERDDp2XgVGjwKareVkuII65WCGACW7ZQSvHgJIYOg43wg7udYgLmY0 qoLw== X-Gm-Message-State: AOAM532G02sPdECSpodkVZ2MX4/yqBB+EYGAiWzNTfXf81HkxwD74/Qa DEmy/3VDFuMDJ1M9mVMf1n1NaQ== X-Google-Smtp-Source: ABdhPJx88ZEAuzCMecJkvkFceLyooIkm16aVnjPesB1obT9t7K00kc35hC5MHq7VHsp1INz4DWoreQ== X-Received: by 2002:a17:906:d555:b0:6da:ac8c:f66b with SMTP id cr21-20020a170906d55500b006daac8cf66bmr12918155ejc.107.1650368098510; Tue, 19 Apr 2022 04:34:58 -0700 (PDT) Received: from localhost.localdomain (xdsl-188-155-176-92.adslplus.ch. [188.155.176.92]) by smtp.gmail.com with ESMTPSA id ce21-20020a170906b25500b006e89869cbf9sm5608802ejb.105.2022.04.19.04.34.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 04:34:58 -0700 (PDT) From: Krzysztof Kozlowski To: Greg Kroah-Hartman , "Rafael J. Wysocki" Subject: [PATCH v7 07/12] spi: Use helper for safer setting of driver_override Date: Tue, 19 Apr 2022 13:34:30 +0200 Message-Id: <20220419113435.246203-8-krzysztof.kozlowski@linaro.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220419113435.246203-1-krzysztof.kozlowski@linaro.org> References: <20220419113435.246203-1-krzysztof.kozlowski@linaro.org> MIME-Version: 1.0 X-Mailman-Approved-At: Tue, 19 Apr 2022 13:52:23 +0200 Cc: linux-hyperv@vger.kernel.org, Stuart Yoder , linux-pci@vger.kernel.org, linux-remoteproc@vger.kernel.org, alsa-devel@alsa-project.org, Peter Oberparleiter , Vineeth Vijayan , Alexander Gordeev , "K. Y. Srinivasan" , linux-clk@vger.kernel.org, linux-s390@vger.kernel.org, Wei Liu , Stephen Hemminger , Dexuan Cui , Andy Shevchenko , Andy Gross , NXP Linux Team , Christian Borntraeger , virtualization@lists.linux-foundation.org, Heiko Carstens , Vasily Gorbik , linux-arm-msm@vger.kernel.org, Haiyang Zhang , Mark Brown , Rasmus Villemoes , Bjorn Helgaas , Bjorn Andersson , linux-arm-kernel@lists.infradead.org, Mathieu Poirier , linux-kernel@vger.kernel.org, linux-spi@vger.kernel.org, Krzysztof Kozlowski , Sven Schnelle , Linus Torvalds X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" 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 890ff46c784a..be8f1a1e21b2 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