Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp1056539pxm; Wed, 23 Feb 2022 17:01:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJz2xVLOlrjG6sx9bJWetEGtSgMRFMH77kssKDr/ZbFdMUJRYT5Vc42om+Y4PU/cOrNvVgdU X-Received: by 2002:a63:ec46:0:b0:35e:7865:ac76 with SMTP id r6-20020a63ec46000000b0035e7865ac76mr329849pgj.453.1645664492775; Wed, 23 Feb 2022 17:01:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645664492; cv=none; d=google.com; s=arc-20160816; b=w1sKLDwLEQJ85ge6rA+I/4y48k090SpNYznY6RTaXxpoxhIhEAYOzoYCDmhuMKqPCr r5wXHyJZAYe7SduGjsOLJF9t9uRvdFN2hIZBwYQvZCnIYq1xlfIl1GlEqG7G8xGOiu7O Dc4iUJsV9jZhPVhNmHzNWHcdk+ejGRU/2dN8vN7u6LtdevMV5LEdFIQKPhMsQTtJiSJo jYQrx1Sfa9Kub5ixWS8u/8LPNa8L/qoOifsK++XaU3AOIV69cmVhITF2exoZteCT1eX4 g1OMhyvqJJ00l/v/Blp/aaLya+GGlUojpbefxpVJqofi3DUJnA7M+fIAqILE8SxkAhDw Pdeg== 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=7IYTHmQXzsIW766tCpVJPfNTfO+AmvxjDRcTslL8YGA=; b=fTD7OwVCvL+jhum1c2NA8jW2U/9RvG5aX6hdfLqZJanVDy5VbBD8pcLr+S/WuYLE/W 3fnUcVRuFU6BvR8Rdx21FlnBrYlmaNeWiCteopntQGzKLcVFKo5RZ6ueb/PKyT25JhNa euxO6lg8MQavvbtA6rddo3xnvTigCJD7jMgb1d7FrYI+pPtdFS5SiFNk66fjSF2Rwit+ CHTHD+ljZlgZf7CkeN1K+2gX1pxNLctKQ5WqA+SOqenqeqUAZ49xYGJYIO7DwKO1fhDS HDgYHAKZRgXP0tXnD2Kbc2f1c+jO+99EOmSRbXOQN2BV7F1pXHndWzEuguTXLkqwWhTC RmrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=J8x2Ejlj; 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=canonical.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id m16si1061073pfc.211.2022.02.23.17.01.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Feb 2022 17:01:32 -0800 (PST) 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=@canonical.com header.s=20210705 header.b=J8x2Ejlj; 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=canonical.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1C3151342E4; Wed, 23 Feb 2022 16:52:23 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244297AbiBWTQY (ORCPT + 99 others); Wed, 23 Feb 2022 14:16:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244305AbiBWTQS (ORCPT ); Wed, 23 Feb 2022 14:16:18 -0500 Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21E0F40E6A for ; Wed, 23 Feb 2022 11:15:50 -0800 (PST) Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) (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 AFF223F1D0 for ; Wed, 23 Feb 2022 19:15:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645643739; bh=7IYTHmQXzsIW766tCpVJPfNTfO+AmvxjDRcTslL8YGA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=J8x2EjljgeeQCSRe+JhdeC2s8js7YbAQAnJjBQ4rm3jfFhkRX0jyCgfXYG9cawMZo 10CcRPVMClFkwDorda1J3Ni4vObX4YNelb+NysVadbD/cVJ573veLbzT6iIJdyWwbl u7oWSggEFrtIRKovYG8ywiWw8IFBnfrWZ+uiaIfsEHGiRjmr9AtOy3QIf2/FgBWdHl FgI5Llo4hetfyxRD/VL+9vrVlCgdYJJ+OYArvp1g9i8AfMqXgNVJE6LW6EAXf7vgjv T3zC4N6dv32Xacu58JdUJUxQegkbmD2m+R0cS62IZgOSibz7sqKU1fDZNmKrprYkzl p/Apto6MMepqg== Received: by mail-ed1-f72.google.com with SMTP id r11-20020a508d8b000000b00410a4fa4768so13937431edh.9 for ; Wed, 23 Feb 2022 11:15:39 -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=7IYTHmQXzsIW766tCpVJPfNTfO+AmvxjDRcTslL8YGA=; b=AxT3Kbb/JPERByzBekToKg+ac8AOPIe5jrv062XHOgIc5tEbZ00WdvQjbbpvQcCF4D WZGJ5xwfLZHtHRw3dBGJ1Bz26O1H/BO8ybsfBie6/LvCD6VyNbhg6oFV8IIAyn1GN25X pTa991Cjzx+Wf5NSlkLuoQ7Vzr/tyrF+GBff++yK1WAkjfR2CaGp9qoPiFJPhMqMIFKx +WJNAhGfD8ljMRzR039fyX7KCSwjoSpg69ZJEUnicqosNf7gGYLy09O5RrmV20kz+zzV xviVZK9BKgct/6XIIbp7669H9vb6bmT55qYnaxwRbv7wIm5dZLbDpA4v3sZEMWUN1kw5 Tu1w== X-Gm-Message-State: AOAM532C2hurOtzG+H/Jx07BM59M6ZYELUAINlUqUftu2/mVWtUn/fB/ 9km8fOOKqq0V8g6OD2xkb00QqifZWC+ApVqyhxp0cwc4Gb2kIoLeVXsqb+XL0qpy2rPGjUf2Ovo 9ZWcVrR1luZtrJqCEFT0dCE/NQ7+MAs1HVIHVA8e5Vg== X-Received: by 2002:a17:906:b57:b0:6ce:e31a:524 with SMTP id v23-20020a1709060b5700b006cee31a0524mr898065ejg.290.1645643723446; Wed, 23 Feb 2022 11:15:23 -0800 (PST) X-Received: by 2002:a17:906:b57:b0:6ce:e31a:524 with SMTP id v23-20020a1709060b5700b006cee31a0524mr898038ejg.290.1645643723190; Wed, 23 Feb 2022 11:15:23 -0800 (PST) Received: from localhost.localdomain (xdsl-188-155-181-108.adslplus.ch. [188.155.181.108]) by smtp.gmail.com with ESMTPSA id b3sm208368ejl.67.2022.02.23.11.15.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Feb 2022 11:15:22 -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 v2 07/11] spi: use helper for safer setting of driver_override Date: Wed, 23 Feb 2022 20:14:37 +0100 Message-Id: <20220223191441.348109-1-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220223191310.347669-1-krzysztof.kozlowski@canonical.com> References: <20220223191310.347669-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, 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 for seting driver_override to reduce amount of duplicated code. Remove also "const" from the definition of spi_device.driver_override, because it is not correct. The SPI driver already treats it as dynamic, not const, memory. Signed-off-by: Krzysztof Kozlowski --- drivers/spi/spi.c | 20 ++++---------------- include/linux/spi/spi.h | 2 +- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 4599b121d744..0c7e2c34f4a3 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -74,27 +74,15 @@ static ssize_t driver_override_store(struct device *dev, 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; + int ret; /* 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; - - 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); + if (ret) + return ret; return count; } diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h index 7ab3fed7b804..01224d07aaff 100644 --- a/include/linux/spi/spi.h +++ b/include/linux/spi/spi.h @@ -184,7 +184,7 @@ struct spi_device { void *controller_state; void *controller_data; char modalias[SPI_NAME_SIZE]; - const char *driver_override; + char *driver_override; int cs_gpio; /* LEGACY: chip select gpio */ struct gpio_desc *cs_gpiod; /* chip select gpio desc */ struct spi_delay word_delay; /* inter-word delay */ -- 2.32.0