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: 545334 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 37FDBC3527E for ; Wed, 23 Feb 2022 19:14:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244231AbiBWTOy (ORCPT ); Wed, 23 Feb 2022 14:14:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244239AbiBWTOx (ORCPT ); Wed, 23 Feb 2022 14:14:53 -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 72727403EF for ; Wed, 23 Feb 2022 11:14:25 -0800 (PST) Received: from mail-lj1-f197.google.com (mail-lj1-f197.google.com [209.85.208.197]) (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 7C85B4005E for ; Wed, 23 Feb 2022 19:14:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645643660; bh=fyZde4QL+5WSjtUcZmZyQ9LOCmYULjkOm0dq/nBIuzo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qBQokoKPizZLZ2UnvkN5VQded3OZUDYY/lI3AaUtyPCslWX9C8iYDV79FjJVKWgsR S6DYndF+9pGS3EYK+tASbPwfg0i6rPObQ0OGnIUxWoqIphXizAE5TDRt00hwmM8NLH VHo0WpxTX0P3aIHQQUhLqDYj7BPdKiQ9zHYhymZR3lq9HC9HmnQsezrvHNBImknJ2x zobPILGpeX5aE/Up+rM51f2ebl7NLC9uUuxOgHVyJdCoY6/ByyuFzqKg27kicoh7WY FLg5r2wwE/jCCkn8vhSzl42QHXKp9fTuQOhm7eE850mUKEAdODehcNpKh7HgpxCoNf QH/ky5jmbWxZQ== Received: by mail-lj1-f197.google.com with SMTP id n9-20020a2e82c9000000b002435af2e8b9so7753601ljh.20 for ; Wed, 23 Feb 2022 11:14:20 -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=hhyc+3Ho+oWyX1W/F5gHSdjQArUd3e1eSjT35P3A4dliJdvwbqi0cTdBOu32x/dngZ g2JEQj4obrnDgOgov7VYulOgTW8yGrbYhJxAu4oz2f6NcC/UmNxJDExa+7sWOZlSST3W u2H5R5iq7GDwLFPEM3Ub3J0ntWjs+zCoBlk5bHnnvuRFUHE2Gswwi6GpM4mMnTWF7PKw AZcUmPtmgq6wL5UTIRyxdievScs8KZaGMp+lc+0ofuw9qoDrg8/FRLDVVlSzTXOVzLrB 1cj407mEc5fExLF3Z9hINq3AeW1FszcFbIYtHmbT1pw4AWgC3/TyaoqVke6vQ0tuVjHk 1CWg== X-Gm-Message-State: AOAM532tKmOjKySsC36PIhtU4hQlK8sdIQwMhLEU+1UABsopqO04/kOW FXKZRWCUgMnplgFY91DdoeelJ4GxR4FJ4a4N99JAbv23ZfC5o9mHWmN8KWjCT6fRKGh7sku95Ch YX7IwAq6F1hq0Xp1bqEcC8WYN0rD5Bb7t78DXG2HPHag= X-Received: by 2002:a17:906:a384:b0:6ce:c3f4:c59a with SMTP id k4-20020a170906a38400b006cec3f4c59amr870098ejz.580.1645643635871; 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-arm-msm@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; } From patchwork Wed Feb 23 19:13:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 545333 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 6F858C433F5 for ; Wed, 23 Feb 2022 19:14:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233132AbiBWTPF (ORCPT ); Wed, 23 Feb 2022 14:15:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244275AbiBWTPC (ORCPT ); Wed, 23 Feb 2022 14:15:02 -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 26F314131A for ; Wed, 23 Feb 2022 11:14:33 -0800 (PST) Received: from mail-lj1-f199.google.com (mail-lj1-f199.google.com [209.85.208.199]) (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 49F6140307 for ; Wed, 23 Feb 2022 19:14:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645643669; bh=rf7a9EFQwPOyocENu81tYUT+5dnJvDmCZPPvLR/17AA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nnCx6jS0XwjtguAvpGWTRIg6MxzCbqvy/JPPbAkS5/N5+uwhYPA26MXEtosgEmpy8 tPZ3hPPsJRbRcShIN/oVV5WBWHAPd5Ur+JJfhaZYSuZ+6O1Rhf2imWnEQLKCbctiw0 V8p/XGylVi69KKeMndh5q5qJ+xnLLxNK0LXt4eq/aRxw08IwGKMUQl/sRpZGcniHpY yIjhNughPnSLB/P18ma5fDzRCxddqSIZGkDIvs0lPJY8pEKOUP8h+GJ4bmMO0C3Bue Wd/7zl5OGPhN/ci0Vw44+DVqCSX2694MTc7yi7zDePxG9mt0i846kmaETP4jWEHusE VlLfJRHL0RYgw== Received: by mail-lj1-f199.google.com with SMTP id 6-20020a2eb946000000b002463d2915d2so5464901ljs.9 for ; Wed, 23 Feb 2022 11:14:29 -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=rf7a9EFQwPOyocENu81tYUT+5dnJvDmCZPPvLR/17AA=; b=SgwcElAAIaNh0dKqySFgecfC+6721tB+EsNWMRh4xrlKZ/dqqRxjpukm85o9fi9KUa SKKvTQoGSLeRpT9jUKgcZEF7XVSKUdWnPUkTXTwVBrv35dMoZVvG4uMsN8W9oRRKT0Ly 7HL9h7VyUA968SYPHoZyI+8SEw+B6CgnyPeUaqPzsvhWYSlenZW/CnK31gIU+O69BHX1 zibSTN4s8kggRpiEVkG418hFv8CwiKpa1/LN5mj0Hy/86GRBZPvZT97NSdzVoRZcHXNV Y5iwGQtcozbyWgLST7Se7CK8PN97lW2Au6ZO1Wmw8C8Rb1csxkb7N+Fn1M0EgM++Mz92 hn4A== X-Gm-Message-State: AOAM531ikkpZG7bFLhSejcNKFp+54VE697joTCR1DaOeLh7mOTC1hoyg jec/IKAwgi53rnmlOBiQKzCQt3ETnVLoG7jq/pTd61mvc25fZYoYM7ESZQh+3W3PogPa3XYJKWq SEjZoStCjMNXFJasMpp0LBCZjo+nAFyL49/+Q9MsWjuc= X-Received: by 2002:a17:906:e244:b0:6cd:24e3:ab8b with SMTP id gq4-20020a170906e24400b006cd24e3ab8bmr856427ejb.633.1645643640106; Wed, 23 Feb 2022 11:14:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJyXgfLS9GHyX1kCvT/o1Mu24QLFIsYnwLPgsBOYcxKH/GiFu7jQtQB6sjAsK4TU39w3xnST4g== X-Received: by 2002:a17:906:e244:b0:6cd:24e3:ab8b with SMTP id gq4-20020a170906e24400b006cd24e3ab8bmr856416ejb.633.1645643639914; Wed, 23 Feb 2022 11:13:59 -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.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Feb 2022 11:13:58 -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 05/11] pci: use helper for safer setting of driver_override Date: Wed, 23 Feb 2022 20:13:04 +0100 Message-Id: <20220223191310.347669-6-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-arm-msm@vger.kernel.org Use a helper for seting driver_override to reduce amount of duplicated code. Signed-off-by: Krzysztof Kozlowski --- drivers/pci/pci-sysfs.c | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index 602f0fb0b007..16a163d4623e 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -567,31 +567,15 @@ static ssize_t driver_override_store(struct device *dev, const char *buf, size_t count) { struct pci_dev *pdev = to_pci_dev(dev); - char *driver_override, *old, *cp; + int ret; /* We need to keep extra room for a newline */ 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'; - - device_lock(dev); - old = pdev->driver_override; - if (strlen(driver_override)) { - pdev->driver_override = driver_override; - } else { - kfree(driver_override); - pdev->driver_override = NULL; - } - device_unlock(dev); - - kfree(old); + ret = driver_set_override(dev, &pdev->driver_override, buf); + if (ret) + return ret; return count; } From patchwork Wed Feb 23 19:14:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 545332 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 82884C433F5 for ; Wed, 23 Feb 2022 19:15:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232798AbiBWTPy (ORCPT ); Wed, 23 Feb 2022 14:15:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232148AbiBWTPx (ORCPT ); Wed, 23 Feb 2022 14:15:53 -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 E0F923FBC4 for ; Wed, 23 Feb 2022 11:15:25 -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-1.canonical.com (Postfix) with ESMTPS id 1F0C63FCA4 for ; Wed, 23 Feb 2022 19:15:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645643724; bh=7IYTHmQXzsIW766tCpVJPfNTfO+AmvxjDRcTslL8YGA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=awSj6NnOb7dvWb+268pcpkaHl/Hy5SRre0u7RG2tgOhEaBPQvNB7o/xPvraygufJx mWLcwMFouA6HzRUlrBUMo0ACHt10trCtoV/EvGX1bekrVeyojmkIQvWb93GPWAfFmu 0IRuA0zFSnTqswk0VmSdTi/xUVdZNm/dNcyEBCO5magr/9QIlSGlilGgBfJHR8HjFj p6Ll0SDMpiF56BsJc/vnPqENXmqi1L+zpQCvCHGnRANoAMIlzpwdtxRpIUi+5bKYVE vbdHBxoJkp7Z4RQgHyx9nnWOY+xx+Kg/6pjfLZ7NWED4+6smfX+Ot37HKbJi2GL9iG f91cyZUauUc0g== Received: by mail-ed1-f69.google.com with SMTP id g5-20020a056402090500b0040f28e1da47so14102304edz.8 for ; Wed, 23 Feb 2022 11:15:24 -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=CoRF551Uxb6vbe+DYeY+7Ea96CcS2Drwv+3Rir6+oSeo/QVXhzVKBtBGMSFr+NR6zj z9C5o9bhhEZiVZRHPLii8o5g/cUTgKkAXh/uc4Lf+GDUklhbrda9Sst2DjLjR1t+rAM7 1EkAZUUxxv0UpDz9XYNI5Ev/OlpkCnW7HYoFSRwLsNpLo38fOHxRcJb2h8O+2US6k8OV MnjBzTV9/BT8J77yCCh88xYM+Dxq1KU6uSo94JS4+j9TtzUUNuUKINjmuEX7M74QddxD qPFdR0Ce87IcKQuqmobajGP2VB0Rk+jUL8GBoZA8WJQ/96bLU0MtF+fqHBsYaB6wb8/q 9R8w== X-Gm-Message-State: AOAM531dHUIoHTAk+xuRXmh4zy+LYaVRk9gj+Z0J7O+FvvPZrikVnoFq zivtyo1zFQxACUMXMP3pi3WYWYjA+w1LQkT6FM5/vhuplaQIcxLCvS4crI0zEISlJijJs3T7lfV NM9ETRt1BZxiNdkTWOHxALPA50trW0/gP2PdExSe4KcY= X-Received: by 2002:a17:906:b57:b0:6ce:e31a:524 with SMTP id v23-20020a1709060b5700b006cee31a0524mr898066ejg.290.1645643723446; Wed, 23 Feb 2022 11:15:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJwXaymv6Y03sx5emAtiihVKDslUlZDj5+bUOqZTX2T0tvcmba61MgF/pNNazmHUobDDFmGa2g== 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 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. 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 */ From patchwork Wed Feb 23 19:14:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 545330 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 EB3D9C433EF for ; Wed, 23 Feb 2022 19:15:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244271AbiBWTQW (ORCPT ); Wed, 23 Feb 2022 14:16:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244233AbiBWTQM (ORCPT ); Wed, 23 Feb 2022 14:16:12 -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 941C341FBF for ; Wed, 23 Feb 2022 11:15:41 -0800 (PST) Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.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-0.canonical.com (Postfix) with ESMTPS id F03C03F33A 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=WWBR/3RyyId0ctzqGYcSjorUZAyYEVp2bjQXWveQ/28=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=EEk676dle8KZDUlZhD1fIBWyycHawP48KDRYk9PEW7uLO6SEBzs9rJ3+SvyOjiMdu jifi88tGrog1qVKk0sCTkz+iA0DRYwCnj52ACty1MUFO/6uY2TFl31oi2sO42La9M/ 9b+szQ09tQwJE/QkPWplk18Sq1/ceXabq8k47eLAKvn+Rl6tIouSfrgK5g0sjCcc26 ey5lO6VKte2LAbk5KJl+hcYmcIN+ZghFSe+b9FKyyF5OnfFfpViXEY/SpP8Siyh4ZW UH1cgdJjH7dm3jYBNjBJhGOuz7ezTWE9Z4FNhtB1wyc8PkUU8IKPT4RZy9yHeR8RrU HqElKDtrIJ1YA== Received: by mail-wr1-f72.google.com with SMTP id f14-20020adfc98e000000b001e8593b40b0so9920854wrh.14 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=WWBR/3RyyId0ctzqGYcSjorUZAyYEVp2bjQXWveQ/28=; b=UIMqSGoekMA0I6SPs00pQJM5EDSotAQgo1scyHCnj1pQLuyBJK3fUhYtj79/8v7AOm X7rdO3dYOisXByqPJbHYHLNJbcrR1SL6n6F7hWdWYFJRMoqEWADAC8cijaARe89JkE0C gipZUyw+ETcZnNkDIPd35SapkTjz7xHXWIgi5mCZ3JqavC6XLQkSDqGyAYsI1dsIOdhU p2RHZzszZPRUoYPsK3HQuHvEgENt0mvz2dm+c1ocr4ARwHo95ZjkDsxbKegpXq2pQ5BC wOg04uJzBpDvu8YeGfrQJ/6cViEbDStd91aduWSdXFXOuOwv0/+NbCP0WCVz8oZRJ7VA on/A== X-Gm-Message-State: AOAM532gU/zrnGxdbBWp16FvaENopw8A+LBKuaTaAJbSoaAhuGGVheNI AwKYc3VpAChL5ZAVRd2AJlbTaP1VDbTCdbXRsq3Nm/m73TaAsbh1T/11KAQ6uQkqduRbKUvr4Xk 9jfkNjA1LGBpB1oZiHo+tff0aq+eonGVEUcMpK8ws9F0= X-Received: by 2002:a05:6402:70d:b0:410:ba4d:736f with SMTP id w13-20020a056402070d00b00410ba4d736fmr891854edx.0.1645643727232; Wed, 23 Feb 2022 11:15:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJw8vcySNYfbv43Pk2WXynTAOxXboVgUUSRQKZSxFWxW+kHULs5hedJTU2eFScz4UFZao2eyYQ== X-Received: by 2002:a05:6402:70d:b0:410:ba4d:736f with SMTP id w13-20020a056402070d00b00410ba4d736fmr891811edx.0.1645643727044; Wed, 23 Feb 2022 11:15:27 -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.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Feb 2022 11:15:26 -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 , stable@vger.kernel.org Subject: [PATCH v2 09/11] clk: imx: scu: fix kfree() of static memory on setting driver_override Date: Wed, 23 Feb 2022 20:14:39 +0100 Message-Id: <20220223191441.348109-3-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-arm-msm@vger.kernel.org The driver_override field from platform driver should not be initialized from static memory (string literal) because the core later kfree() it, for example when driver_override is set via sysfs. Use dedicated helper to set driver_override properly. Fixes: 77d8f3068c63 ("clk: imx: scu: add two cells binding support") Cc: Signed-off-by: Krzysztof Kozlowski --- drivers/clk/imx/clk-scu.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/clk/imx/clk-scu.c b/drivers/clk/imx/clk-scu.c index 083da31dc3ea..15e1d670e51f 100644 --- a/drivers/clk/imx/clk-scu.c +++ b/drivers/clk/imx/clk-scu.c @@ -683,7 +683,12 @@ struct clk_hw *imx_clk_scu_alloc_dev(const char *name, return ERR_PTR(ret); } - pdev->driver_override = "imx-scu-clk"; + ret = driver_set_override(&pdev->dev, &pdev->driver_override, + "imx-scu-clk"); + if (ret) { + platform_device_put(pdev); + return ret; + } ret = imx_clk_scu_attach_pd(&pdev->dev, rsrc_id); if (ret) From patchwork Wed Feb 23 19:14:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 545331 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 BDB1EC433FE for ; Wed, 23 Feb 2022 19:15:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244311AbiBWTQO (ORCPT ); Wed, 23 Feb 2022 14:16:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244273AbiBWTQM (ORCPT ); Wed, 23 Feb 2022 14:16:12 -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 20934419A3 for ; Wed, 23 Feb 2022 11:15:40 -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-1.canonical.com (Postfix) with ESMTPS id D1A4240310 for ; Wed, 23 Feb 2022 19:15:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645643731; bh=7X8ZF+SfQI2ha/R62opt5Mpi3EJQ2IXnqtdf8o/szaw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=p+mECjX6IJJhO4alngh2NKhaovPH5X4W3OO38kUkNxUT2vWTDpVENCjXuzvqScJpu yLQHVcD6sjcPv3KqrunR4kxgWZ3Ve7dGEP5gVkxjxPaPH6Tro6nn8KD5v2ARIQcvTY Cu7oVtd6c/KiWei+foQc8SkOXaRoeVvck9cNtORash0Cko4TS8potkk6VoPJeNO8Si R9TkWLWWM9ahvSw5JEHlOMnh3VfkE6R8M5CgGL+ioX7avSaHN1Jy6NVQHj/dgf078H ugxMsQOKMNID7n2qE4oODRPkDbd8JRsmyvxX+prGGx8hZwR3aRRkhI6JUJmxBrOqem anzZeFOh2w6HQ== Received: by mail-ed1-f69.google.com with SMTP id dy17-20020a05640231f100b00412897682b4so12297016edb.18 for ; Wed, 23 Feb 2022 11:15:31 -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=7X8ZF+SfQI2ha/R62opt5Mpi3EJQ2IXnqtdf8o/szaw=; b=mJXUX04LOzs7LVT9fUR0S2TmvLcYBDnH4G/8uZHCzA4hIeZnpMY0eYOiaGrW68dYUv jH2mEmgx16wSNZ4OCEpGak31M+g9ogqwHY1MZ/u6EbuJkRp6MYUm85RYvpcxkgdlLrSM i8KfzZGo8BclIbCOvA7Zu9vmnhbSY0StXuAwwfcfQjM4XBdqciHQJGKoo8pNndWPQwO7 LMs0nEG5A+hgGahcXLX3UTXHRyx0NOYe+izEu99uwkLEY7XKMMbyRQI6KMboqp9HpASD 7/qJ1oOThj23jn+IeHGadDfL99burgxRPaxcImNf9BLSDdzr+TcfowtAP6wTlC5kHgBT K2sw== X-Gm-Message-State: AOAM533j/I+QTpadVJnHJf+uJfZO92/G5waKc+M1lBowkNt2kt+4ynwo DTCvQ+1WHDG/uT7QwBWoTvVJbRMdqZrqS5suQ32S5wdiR2QOtVYjj8GeiD8xGrup5u6zaFU8Mxu 08Fkn6FGkJee3Kde/AXTgikYhk2BcnjzX73uMJtClJtM= X-Received: by 2002:a17:906:130a:b0:6b7:5e48:350a with SMTP id w10-20020a170906130a00b006b75e48350amr887337ejb.184.1645643731002; Wed, 23 Feb 2022 11:15:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJwzAUHN+IckyCUDaf6b+egXxiKcwH4G6el1z4Ve3vQHF0MnEv7U39pYdE62mAB1vpTAj/GhtQ== X-Received: by 2002:a17:906:130a:b0:6b7:5e48:350a with SMTP id w10-20020a170906130a00b006b75e48350amr887325ejb.184.1645643730755; Wed, 23 Feb 2022 11:15:30 -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.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Feb 2022 11:15:30 -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 , stable@vger.kernel.org Subject: [PATCH v2 11/11] rpmsg: fix kfree() of static memory on setting driver_override Date: Wed, 23 Feb 2022 20:14:41 +0100 Message-Id: <20220223191441.348109-5-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-arm-msm@vger.kernel.org The driver_override field from platform driver should not be initialized from static memory (string literal) because the core later kfree() it, for example when driver_override is set via sysfs. Use dedicated helper to set driver_override properly. Fixes: 950a7388f02b ("rpmsg: Turn name service into a stand alone driver") Fixes: c0cdc19f84a4 ("rpmsg: Driver for user space endpoint interface") Cc: Signed-off-by: Krzysztof Kozlowski --- drivers/rpmsg/rpmsg_internal.h | 13 +++++++++++-- drivers/rpmsg/rpmsg_ns.c | 14 ++++++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/drivers/rpmsg/rpmsg_internal.h b/drivers/rpmsg/rpmsg_internal.h index b1245d3ed7c6..c7bd0a3c802d 100644 --- a/drivers/rpmsg/rpmsg_internal.h +++ b/drivers/rpmsg/rpmsg_internal.h @@ -92,10 +92,19 @@ int rpmsg_release_channel(struct rpmsg_device *rpdev, */ static inline int rpmsg_chrdev_register_device(struct rpmsg_device *rpdev) { + int ret; + strcpy(rpdev->id.name, "rpmsg_chrdev"); - rpdev->driver_override = "rpmsg_chrdev"; + ret = driver_set_override(&rpdev->dev, &rpdev->driver_override, + "rpmsg_chrdev"); + if (ret) + return ret; + + ret = rpmsg_register_device(rpdev); + if (ret) + kfree(rpdev->driver_override); - return rpmsg_register_device(rpdev); + return ret; } #endif diff --git a/drivers/rpmsg/rpmsg_ns.c b/drivers/rpmsg/rpmsg_ns.c index 762ff1ae279f..1c9f9cf065b0 100644 --- a/drivers/rpmsg/rpmsg_ns.c +++ b/drivers/rpmsg/rpmsg_ns.c @@ -20,12 +20,22 @@ */ int rpmsg_ns_register_device(struct rpmsg_device *rpdev) { + int ret; + strcpy(rpdev->id.name, "rpmsg_ns"); - rpdev->driver_override = "rpmsg_ns"; + ret = driver_set_override(&rpdev->dev, &rpdev->driver_override, + "rpmsg_ns"); + if (ret) + return ret; + rpdev->src = RPMSG_NS_ADDR; rpdev->dst = RPMSG_NS_ADDR; - return rpmsg_register_device(rpdev); + ret = rpmsg_register_device(rpdev); + if (ret) + kfree(rpdev->driver_override); + + return ret; } EXPORT_SYMBOL(rpmsg_ns_register_device);