From patchwork Sun Feb 27 13:53:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 548300 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 4C55AC433F5 for ; Sun, 27 Feb 2022 13:53:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229768AbiB0NyR (ORCPT ); Sun, 27 Feb 2022 08:54:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229876AbiB0NyQ (ORCPT ); Sun, 27 Feb 2022 08:54:16 -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 706CF13F87 for ; Sun, 27 Feb 2022 05:53:37 -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 06FBE3F1C9 for ; Sun, 27 Feb 2022 13:53:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645970016; bh=qpFiz05rVbRuRAHN9hg8SmLpkD4Xh7SLbxYijfSgBwA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rmhl8qCa+qnn5onf23jA3QCk+bIQPzArdPvkobAwCfvO3QNGdsjkm8CrcW5mUk9e2 RUU5Li3KhDre5xcJNeHBx7FeuyhByRQ5Vxv/Hbitfx+RnOsJCUCM8DtTGAYJZdx4Bd eCnTzVIa2zgEY1FKg+Tvdar1R0e6JnvMLzg9Xqm3eCWR5wDj3ZtZEijYJt/pr4sq/3 bsNVWxbuNTqTfmREDXzTA7IzYJDLql5zdY4S6JNdE2eHoHmomFBWTBN4t7lxwXBS/e xpsodnMv414cQNtq0qGYuVF6nCeWq44xB/AHIFIPfsVVl+I7mQ5NY2v1b4s4gMv/X6 7H7F3yqni22Jg== Received: by mail-ed1-f69.google.com with SMTP id o5-20020a50c905000000b00410effbf65dso4235561edh.17 for ; Sun, 27 Feb 2022 05:53:36 -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=oMOEKf9wPMlcV5OyECyRkEkmRw/pltD3YX58KwNzvbF0SeBdUFdr02AjaYz6aSv4DI /uPA4juinYaP3o4e1Crkr++aa6HjZ7wbe2+5EMhcOIjeBOMtrnVbPzUDteORf6l2DcUa cOop3NPditWdKnsgALVn5YxY+xR46SEhQiAniglrGfVJmspJo9zcJ1TY6tTFEkINqTLd b5uzmbTMyhVAKUF9oiViDJ/VlJ6vdzeyDcrGYFrRSZ3VqZbeJEFDTi06FFx1cTjPu57a /As3gyfvKgbJg0GyrlB7mLK65IJo4qCPm/08QV+dWjYV+Ug0PxJZ0VJnoOjL8u9cn6l9 6zCA== X-Gm-Message-State: AOAM533W/zfM6Pd9QddbovumETTAo3sWJPGYiCwfkwb4CbTltgYQ1DqV BMp3o3foZ1PNhRRuYXIn/4SOgMGvdQQi4pllmvSF+drm3z0qqSwCSSJPqTPas1hXKW9Mm6bnLfh 5TsT20pFqoc82+NeVNhFLjAl64nJOA+8t3fbmgSfQDKY= X-Received: by 2002:aa7:d98a:0:b0:410:b844:7889 with SMTP id u10-20020aa7d98a000000b00410b8447889mr15100885eds.109.1645970015738; Sun, 27 Feb 2022 05:53:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJyhO9Sv0dF420J0f9IZ/pCEaONwOixtXPt4DqHWIJWIfdwGeQCrhRg50N3SHeq1oP4tMC2tSg== 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 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@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.