From patchwork Tue Nov 28 08:42:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 13470675 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 9B19DC4167B for ; Tue, 28 Nov 2023 08:45:45 +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=HqXCvUUd0FbfkqryW1CL2vTHkHjLvTaYzGKOV4AxaxY=; b=JAPO5+TtayunPi C8vzb4hgE6XA0OYrDauFF3PZjqkkNyAq/h9JwkDCcDhoQfMHj9GeBkylesEkUq7AaGuphKhRhORHF UlEemA+qlO36FUV6ibih2R2/nN4+6JhcY66S69Of0+I0SW5918/GONCDi4b53mR040Gt37jCHjNQs c5KsU6IRDiV4adT9gNI1l5xccQT7vd6kown9RIDofTOBGGJpkWrH9lOgUOZnbq+WL/DU5SQRjDQ5L 1vKf3x3vIF5VTd2XEnmtwHmH1ZhtH4Cnzu5loSvnybEO6oO2UAWcJ1Idcg4auhsvZekx85un3b8ZQ FGQGjxQAp1c97VsU8Yrw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r7tiV-004ZZ9-2y; Tue, 28 Nov 2023 08:45:15 +0000 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r7tiM-004ZUu-2u for linux-arm-kernel@lists.infradead.org; Tue, 28 Nov 2023 08:45:08 +0000 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1cf80a7be0aso44338155ad.1 for ; Tue, 28 Nov 2023 00:45:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1701161106; x=1701765906; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kHxxwveZDRAPnfOWumxXktb5k7NbUjKgtDpJO55ZaA8=; b=PXKFi2QOzJsz2CgHi/LoqnR8Ie/p6DdEqgVmloYUxG9zOtoz/nyn1dQu9az0kfCNWq ttQoc9TvlBpTuUBa4v+UtfouISdBKhEeytgk9aOXj27XPLXgNhRmkC+idAd78j9316Zx StNhR8Nac7UpQhrRutd3vPeCkDMfvNplS0dh4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701161106; x=1701765906; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kHxxwveZDRAPnfOWumxXktb5k7NbUjKgtDpJO55ZaA8=; b=LJPnVoZBG+YMzwLp8BTZpMld/rjvmiXtsUVmZh2pAC5IDt6DQrBZ+CikBdEzGrIAuw vvo0BdTsfwldvuIl/H31EIpgOAsEF/VzbjKIhM/yK5QJLB1MzSx0sO6H5IPu+rsYNlPx ULuC6G/o1fP/IE5GlVlpqIAu3Iuf2zSXFD7cKJ8KPaqxrMQ6bOWsIxs/n3BaXRJT9Y7M xylpd6Ra/uhoq3Qbn/8NjfmgnyQiIjaZ6uGTl/YLLBF6kli8pk4O4SzloSsa5rcKPvmo tNOiPXX6J9S8WpgBkRHXqUrJl7sAq4YFGU7yvGDUn+ETNX42ucPZt7X8MWCM9xg+hF9x YVkQ== X-Gm-Message-State: AOJu0Yz5EPHXzcFs817DkvzjJT+U7OCclXplCkd4k9WByEx0TCwzXBNm g0r6tQsVMmv9zs2AH6k7RlhFYQ== X-Google-Smtp-Source: AGHT+IFwNRanqg6iNjPiAn8C7xAInJUbYOtL1AJjn6XOh76hm70XQlF/qqZTYAqMlV2R/DvAZERpiQ== X-Received: by 2002:a17:902:d2c1:b0:1cf:ccc3:c9d7 with SMTP id n1-20020a170902d2c100b001cfccc3c9d7mr7924520plc.3.1701161106024; Tue, 28 Nov 2023 00:45:06 -0800 (PST) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:a990:1e95:a915:9c70]) by smtp.gmail.com with ESMTPSA id j1-20020a170902c08100b001ab39cd875csm8358074pld.133.2023.11.28.00.45.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 00:45:05 -0800 (PST) From: Chen-Yu Tsai To: Rob Herring , Frank Rowand , Krzysztof Kozlowski , Conor Dooley , Matthias Brugger , AngeloGioacchino Del Regno , Wolfram Sang , Benson Leung , Tzung-Bi Shih Cc: Chen-Yu Tsai , chrome-platform@lists.linux.dev, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, Douglas Anderson , Johan Hovold , Hsin-Yi Wang , Dmitry Torokhov , andriy.shevchenko@linux.intel.com, Jiri Kosina , linus.walleij@linaro.org, broonie@kernel.org, gregkh@linuxfoundation.org, hdegoede@redhat.com, james.clark@arm.com, james@equiv.tech, keescook@chromium.org, rafael@kernel.org, tglx@linutronix.de, Jeff LaBundy , linux-input@vger.kernel.org, linux-i2c@vger.kernel.org Subject: [RFC PATCH v3 1/5] of: dynamic: Add of_changeset_update_prop_string Date: Tue, 28 Nov 2023 16:42:30 +0800 Message-ID: <20231128084236.157152-2-wenst@chromium.org> X-Mailer: git-send-email 2.43.0.rc1.413.gea7ed67945-goog In-Reply-To: <20231128084236.157152-1-wenst@chromium.org> References: <20231128084236.157152-1-wenst@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231128_004506_948021_682E6216 X-CRM114-Status: GOOD ( 18.30 ) 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 Add a helper function to add string property updates to an OF changeset. This is similar to of_changeset_add_prop_string(), but instead of adding the property (and failing if it exists), it will update the property. This shall be used later in the DT hardware prober. Signed-off-by: Chen-Yu Tsai --- New patch added in v3. --- drivers/of/dynamic.c | 47 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/of.h | 3 +++ 2 files changed, 50 insertions(+) diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c index f63250c650ca..d22aad938667 100644 --- a/drivers/of/dynamic.c +++ b/drivers/of/dynamic.c @@ -1039,3 +1039,50 @@ int of_changeset_add_prop_u32_array(struct of_changeset *ocs, return ret; } EXPORT_SYMBOL_GPL(of_changeset_add_prop_u32_array); + +static int of_changeset_update_prop_helper(struct of_changeset *ocs, + struct device_node *np, + const struct property *pp) +{ + struct property *new_pp; + int ret; + + new_pp = __of_prop_dup(pp, GFP_KERNEL); + if (!new_pp) + return -ENOMEM; + + ret = of_changeset_update_property(ocs, np, new_pp); + if (ret) { + kfree(new_pp->name); + kfree(new_pp->value); + kfree(new_pp); + } + + return ret; +} + +/** + * of_changeset_update_prop_string - Add a string property update to a changeset + * + * @ocs: changeset pointer + * @np: device node pointer + * @prop_name: name of the property to be updated + * @str: pointer to null terminated string + * + * Create a string property to be updated and add it to a changeset. + * + * Return: 0 on success, a negative error value in case of an error. + */ +int of_changeset_update_prop_string(struct of_changeset *ocs, + struct device_node *np, + const char *prop_name, const char *str) +{ + struct property prop; + + prop.name = (char *)prop_name; + prop.length = strlen(str) + 1; + prop.value = (void *)str; + + return of_changeset_update_prop_helper(ocs, np, &prop); +} +EXPORT_SYMBOL_GPL(of_changeset_update_prop_string); diff --git a/include/linux/of.h b/include/linux/of.h index 6a9ddf20e79a..c69bc7da380e 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -1601,6 +1601,9 @@ static inline int of_changeset_add_prop_u32(struct of_changeset *ocs, { return of_changeset_add_prop_u32_array(ocs, np, prop_name, &val, 1); } +int of_changeset_update_prop_string(struct of_changeset *ocs, + struct device_node *np, + const char *prop_name, const char *str); #else /* CONFIG_OF_DYNAMIC */ static inline int of_reconfig_notifier_register(struct notifier_block *nb)