From patchwork Wed Mar 16 15:07:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 12782838 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 D532CC433EF for ; Wed, 16 Mar 2022 15:10:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=EwTnAJDw4G03246gaO+I2ve1ZcTxPApJAXrbJ19V4tc=; b=2r+YFQB0wwBgdp mT2BoxmbxHlbDjrOO2QuyJUYpY30XfDKiVihe8kuAcV2Dvo8dluvNxMS+k0MlslYxQg+MsCCzlgrH e7ecEO6bzQJq5/lftJlDZdZNugMAgo2scqz6WFiJHDIkhqFIUmp9hIsgGChUqyJmIoQVg9eP3oS9N FJFAPCamhYhXam53cNjQVI5jcPT03y/1s43in/PJnToRDZOK4T7Ykx0hsCO95Jp7hPHM4vMSJyyGB P0oK2otcNLiuJyN2sBsXIJirP/uPMtNyQfqCdHl1ub5rO11ejF/VABdo4H9bxIH4q0T75j4IjkxWi 4Hh0etWL4y7v1j11dwJA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nUVGr-00DQ9m-Kc; Wed, 16 Mar 2022 15:09:06 +0000 Received: from smtp-relay-internal-1.canonical.com ([185.125.188.123]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nUVGi-00DQ7J-Hh for linux-arm-kernel@lists.infradead.org; Wed, 16 Mar 2022 15:08:58 +0000 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (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 4C12B3F1E5 for ; Wed, 16 Mar 2022 15:08:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1647443335; bh=yPtLMahnwKOtCcXgH/ktoILLnjecC9LZzwZsY57u2dU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ftMAJmmPbXItGZhosSt7kztlKjwAy37ZYdveOU4ZWzeW9HQuFIu2Utb49ON/1b298 yWNW0nkHqT6JrbbklEI4WN1t4PZZJ6bSNlUG91LNbihiudz1sYhd+ci7qXZ+572D0R da4/3IV4l1J7YRJD1pUM2UnPPKDiHkiWmGbXGFRlVZS/VpRZfqQ5SPpc8YWnwGO5OO 9oSxLv7N5daV0WqgcG+P7hK6TU0tjUjPnk7XjWCGXQSwrkdB1OHSr9r8zn3F8AJ26b hwv4+CYATlanC9Ei9R9ANceGW02NLo+aYasl4vkEST03F+f6lnm2+2zIJoHD8rz2HJ Y+R9SffLHAtCQ== Received: by mail-wm1-f70.google.com with SMTP id q6-20020a1cf306000000b0038c5726365aso1156453wmq.3 for ; Wed, 16 Mar 2022 08:08:55 -0700 (PDT) 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=yPtLMahnwKOtCcXgH/ktoILLnjecC9LZzwZsY57u2dU=; b=0tme57crGGdwSLm61/OKpWooOh6F96j1h3oPKp6rNrWJG4LwVRbj5BVYX/024ofCPY d9kvdIT9v7z3nnq0fhqpqjzUMXz6/yV4FF4Y2NMw6PBc2gx33LzkSQ2bc0GQ12JJwgic ID9yYwpAfwHlRjnDYj6HbzmvmS7u7VfVFHkvW+OFgsCgRtjSb+rJLIGM2O8EiMrwEDqB uncBxY4qaV1RcXNK+bCkNje37Fwfay+YATy25YACnv1rqf2n7TabdCqMz/2P7h0kij3v Xx1UdbeEh8LSzPJBYwQGF3PelxzV7rEdVIhF3SoiY/+VwYG28XdOy9SDj9NL/IVSjayP yO8w== X-Gm-Message-State: AOAM533t2VcXV9rZIPSwEgB9CHzybzdW/S6WDqVhSR88HCOyBRIkvnaz B5hL9Iex7GpzsHyC7YcHekNzZiaylT/CojRIMRbDrM4Vwjat87h5qVPW7UIu3z5r//gTpFIp4lB A56CbXVGy+XcBzt95T2ulQyNHjgMLgn2bjnZztRzUbXP0UhtHcfBf X-Received: by 2002:a05:600c:1e1e:b0:38b:b31f:7fc with SMTP id ay30-20020a05600c1e1e00b0038bb31f07fcmr6700405wmb.191.1647443335038; Wed, 16 Mar 2022 08:08:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyLttuQcgADlzoGu5HiDZ52KZb2YEjo0lDq9KqKlAOh9CGx+bAznJO89SsLTaClQchjThu5dg== X-Received: by 2002:a05:600c:1e1e:b0:38b:b31f:7fc with SMTP id ay30-20020a05600c1e1e00b0038bb31f07fcmr6700371wmb.191.1647443334858; Wed, 16 Mar 2022 08:08:54 -0700 (PDT) Received: from localhost.localdomain (78-11-189-27.static.ip.netia.com.pl. [78.11.189.27]) by smtp.gmail.com with ESMTPSA id u18-20020adfdd52000000b001f04e9f215fsm1895105wrm.53.2022.03.16.08.08.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 08:08:53 -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 v5 07/11] spi: Use helper for safer setting of driver_override Date: Wed, 16 Mar 2022 16:07:59 +0100 Message-Id: <20220316150803.421897-1-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220316150533.421349-1-krzysztof.kozlowski@canonical.com> References: <20220316150533.421349-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220316_080856_777349_CE23CC7E X-CRM114-Status: GOOD ( 18.45 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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 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