From patchwork Wed Feb 23 19:13:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 12757411 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 3C601C433FE for ; Wed, 23 Feb 2022 19:14:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244240AbiBWTO6 (ORCPT ); Wed, 23 Feb 2022 14:14:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244200AbiBWTOr (ORCPT ); Wed, 23 Feb 2022 14:14:47 -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 F1CAF41626 for ; Wed, 23 Feb 2022 11:14:08 -0800 (PST) Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) (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 D39B03FCAA for ; Wed, 23 Feb 2022 19:13:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645643636; bh=fyZde4QL+5WSjtUcZmZyQ9LOCmYULjkOm0dq/nBIuzo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=E7+KpWsQV9AOBbZBgjzPNC79E0xBSpBSjsfCrkoymIVPZf7jxulrXCeFKPbGRX9uU 2URokUznfwhO4eZARh5HetTPXPLtj6fGrufY0PaoDtHj5QaKUHtLTrh88RE5oRuroy NbuoX8+mDq8a+4G+u4MPt4KD2EARwgNWqoNOAQk66Dps6MFgiD8tgPjctbWZIt8YXF aXJwysD1+DY4bWQ1OlEyl/l9o9ueTKKy1PwvcFosJWwL7KzkqtzH/ZZClmmtDdmSsA EHanc9or8sNu4vEQN9yoPwbdeKryeTBnn4o9sInXVNL5Wz4SjurohJ4GZnpVk3Bt9M zi/i2/Bx0zzoQ== Received: by mail-ed1-f71.google.com with SMTP id l24-20020a056402231800b00410f19a3103so14098977eda.5 for ; Wed, 23 Feb 2022 11:13:56 -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=fyZde4QL+5WSjtUcZmZyQ9LOCmYULjkOm0dq/nBIuzo=; b=Wco37TaUOXlg4LiGeM8hrm4vgM45Nm9aKBgmmLkSRx3ck5ZgnA2T4t2gi+09zkrPux 60Z2FT5y6QARpBoaCmK8HtpOPzfpNlfXDG4BcupGiM5696f2lhcLRcnVEdMGjvDoFsmN 8RfkUXGEu6V3jXduhTIhGQxu2CpQLT+kkayDAdUAUCc4BQm8S+QsMxFfFRRvXMg5pdrf YSh90qgm71WRVA16hkpLgyhUDWM3zCdLnaPLt8f3PA7VKiq4f69keZq3s27AJDFebYlB vLNf+CyaK0BNPxaDRNFEtFDtIKE2RCLEtb8ksbjEaJQEVDaUbptfOy1QiHKgN09+tUwn S5ng== X-Gm-Message-State: AOAM5330ZYkscMyJaJ7oN++F78kXPwYFwfkJtk/wvfByeZYewfHz3123 VR5r1+Xt+LPmAkVUryKLNNgWVxtXerftyXPQw+VhVejCf0q78iwEf5DrZ2C6ynuzHnM7g9xnN8/ LVy9IbKuHbA3SWsmOAvfcmSiW/tox42lONnTZ/DGY8c6lJyE= X-Received: by 2002:a17:906:a384:b0:6ce:c3f4:c59a with SMTP id k4-20020a170906a38400b006cec3f4c59amr870057ejz.580.1645643635867; Wed, 23 Feb 2022 11:13:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJwQC18HONgcYdOr4fLdW/4QMQU7ra3n8dm0IepMHQhTlzr1OkJDjXXGMuSAKvUFTDXd0c3row== X-Received: by 2002:a17:906:a384:b0:6ce:c3f4:c59a with SMTP id k4-20020a170906a38400b006cec3f4c59amr870048ejz.580.1645643635630; Wed, 23 Feb 2022 11:13:55 -0800 (PST) Received: from localhost.localdomain (xdsl-188-155-181-108.adslplus.ch. [188.155.181.108]) by smtp.gmail.com with ESMTPSA id q5sm212611ejc.115.2022.02.23.11.13.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Feb 2022 11:13:54 -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 03/11] fsl-mc: use helper for safer setting of driver_override Date: Wed, 23 Feb 2022 20:13:02 +0100 Message-Id: <20220223191310.347669-4-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 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org Use a helper for seting driver_override to reduce amount of duplicated code. Signed-off-by: Krzysztof Kozlowski --- drivers/bus/fsl-mc/fsl-mc-bus.c | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/drivers/bus/fsl-mc/fsl-mc-bus.c b/drivers/bus/fsl-mc/fsl-mc-bus.c index 8fd4a356a86e..d93f4f680f82 100644 --- a/drivers/bus/fsl-mc/fsl-mc-bus.c +++ b/drivers/bus/fsl-mc/fsl-mc-bus.c @@ -166,8 +166,7 @@ static ssize_t driver_override_store(struct device *dev, const char *buf, size_t count) { struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev); - char *driver_override, *old = mc_dev->driver_override; - char *cp; + int ret; if (WARN_ON(dev->bus != &fsl_mc_bus_type)) return -EINVAL; @@ -175,22 +174,9 @@ static ssize_t driver_override_store(struct device *dev, if (count >= (PAGE_SIZE - 1)) return -EINVAL; - driver_override = kstrndup(buf, count, GFP_KERNEL); - if (!driver_override) - return -ENOMEM; - - cp = strchr(driver_override, '\n'); - if (cp) - *cp = '\0'; - - if (strlen(driver_override)) { - mc_dev->driver_override = driver_override; - } else { - kfree(driver_override); - mc_dev->driver_override = NULL; - } - - kfree(old); + ret = driver_set_override(dev, &mc_dev->driver_override, buf); + if (ret) + return ret; return count; }