From mboxrd@z Thu Jan 1 00:00:00 1970 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 8CE60D1AD5D for ; Wed, 16 Oct 2024 14:00:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Subject:CC:To: From:Date:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=QFUW5QtWwiAAoPHOBLtZjFvfpzfQ9bOt75pgsSUGk4A=; b=jzBG/Z4nlsT9t83+ww5r4Rfsun 2QDCW9IAhSSyqT6Ncfu4wD5x4H2n+X/i7Wk6Ec7NoRTXDGwKTUqZD9ktPRESwF/60jEosQnOy0wrq ZuZ+RFIfPqb/CrwneuKdtBDJs/t8R+29uyxzXdJSBbnA0ahdaUk9o7ce5rv7gzcH5l4xMbs+oa85d l+wHVWEu9i/SRFUE2yoX0bZC9yUXd6ccbwEEBulL7hQqTSafO/uvu/AJHf6GyM5EkWp1O1mjTzn6H mlMWJ55TEamkb70hnjFdeE0vWpM/LlZqnSyRxkEsEVPv3+I+I/cgDWLUZPy0+K6+u2UzCgPrOzcV2 eUty7Iuw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t14Zt-0000000C0wP-2plP; Wed, 16 Oct 2024 14:00:41 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t14YU-0000000C0dT-0idB for linux-arm-kernel@bombadil.infradead.org; Wed, 16 Oct 2024 13:59:14 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:Content-Type :MIME-Version:References:In-Reply-To:Message-ID:Subject:CC:To:From:Date: Sender:Reply-To:Content-ID:Content-Description; bh=QFUW5QtWwiAAoPHOBLtZjFvfpzfQ9bOt75pgsSUGk4A=; b=Fy2QVqmRx21VWt3OUqrxKL2I9G Vx7SEI566tlg9nivyy1ECTE1FgLlKE3hF7TVr7IjwI2IwvKtWpPXCBbnrnQIQIHPbAD9BS+1dCITQ OlTqu2ijiNZpH642f/MVLst8OBPz7DnTysmMGohHbJQ9FEG+3TR+A3QJxby7k25FBvNamgHqFlTsx 8V48kfTxU+0owfv0kB7CvmavUyyC2hgNuMI3QOEOM6uosjrjN6SCEr/xS0qaPdfw8WpIdPaVChewk QZPXlqaLfa1ysy7JsUi1l0mrZ+0s3YQa34CezhbthLe37abPDR7GFfRBJ4EkGZnepN7wivimjwZvI MQxJ0ubg==; Received: from frasgout.his.huawei.com ([185.176.79.56]) by desiato.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t14YQ-00000006pK6-3Rob for linux-arm-kernel@lists.infradead.org; Wed, 16 Oct 2024 13:59:12 +0000 Received: from mail.maildlp.com (unknown [172.18.186.216]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4XTCGw6RFvz6D8Y7; Wed, 16 Oct 2024 21:58:16 +0800 (CST) Received: from frapeml500008.china.huawei.com (unknown [7.182.85.71]) by mail.maildlp.com (Postfix) with ESMTPS id 54E9E140B67; Wed, 16 Oct 2024 21:58:54 +0800 (CST) Received: from localhost (10.203.177.66) by frapeml500008.china.huawei.com (7.182.85.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Wed, 16 Oct 2024 15:58:52 +0200 Date: Wed, 16 Oct 2024 14:58:51 +0100 From: Jonathan Cameron To: Krzysztof Kozlowski CC: "Rafael J. Wysocki" , Daniel Lezcano , Zhang Rui , Lukasz Luba , Amit Kucheria , Thara Gopinath , Thierry Reding , Jonathan Hunter , Vasily Khoruzhick , Yangtao Li , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , , , , , , , Chen-Yu Tsai Subject: Re: [PATCH v4 2/6] thermal: of: Use scoped memory and OF handling to simplify thermal_of_trips_init() Message-ID: <20241016145851.00004e90@Huawei.com> In-Reply-To: <20241010-b4-cleanup-h-of-node-put-thermal-v4-2-bfbe29ad81f4@linaro.org> References: <20241010-b4-cleanup-h-of-node-put-thermal-v4-0-bfbe29ad81f4@linaro.org> <20241010-b4-cleanup-h-of-node-put-thermal-v4-2-bfbe29ad81f4@linaro.org> Organization: Huawei Technologies Research and Development (UK) Ltd. X-Mailer: Claws Mail 4.1.0 (GTK 3.24.33; x86_64-w64-mingw32) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.203.177.66] X-ClientProxiedBy: lhrpeml500004.china.huawei.com (7.191.163.9) To frapeml500008.china.huawei.com (7.182.85.71) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241016_145911_104042_DDB4530C X-CRM114-Status: GOOD ( 24.12 ) 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 On Thu, 10 Oct 2024 20:06:18 +0200 Krzysztof Kozlowski wrote: > Obtain the device node reference and allocate memory with > scoped/cleanup.h to reduce error handling and make the code a bit > simpler. > > The code is not equivalent in one minor aspect: outgoing parameter > "*ntrips" will not be zeroed on errors of memory allocation. This > difference is not important, because code was already not zeroing it in > case of earlier errors and the only caller does not rely on ntrips being > 0 in case of errors. > > Signed-off-by: Krzysztof Kozlowski Trivial unrelated comment inline + maybe return_ptr() is the way to go as Chen-Yu mentioned. Reviewed-by: Jonathan Cameron > --- > > Cc: Jonathan Cameron > Cc: Chen-Yu Tsai > > Changes in v4: > 1. Significant change: kzalloc() also with scoped-handling so the entire > error handling could be removed. > 2. Due to above, drop review-tags (Chen-Yu, Jonathan). > > Changes in v2: > 1. Drop left-over of_node_put in regular exit path (Chen-Yu) > --- > drivers/thermal/thermal_of.c | 31 ++++++++----------------------- > 1 file changed, 8 insertions(+), 23 deletions(-) > > diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c > index f0ffc0e335ba9406f4fd858d6c561f9d23f4b842..37db435b54b124abf25b1d75d6cc4fb75f1c1e5c 100644 > --- a/drivers/thermal/thermal_of.c > +++ b/drivers/thermal/thermal_of.c > @@ -95,11 +95,9 @@ static int thermal_of_populate_trip(struct device_node *np, > > static struct thermal_trip *thermal_of_trips_init(struct device_node *np, int *ntrips) > { > - struct thermal_trip *tt; > - struct device_node *trips; > int ret, count; > > - trips = of_get_child_by_name(np, "trips"); > + struct device_node *trips __free(device_node) = of_get_child_by_name(np, "trips"); > if (!trips) { > pr_err("Failed to find 'trips' node\n"); > return ERR_PTR(-EINVAL); > @@ -108,36 +106,23 @@ static struct thermal_trip *thermal_of_trips_init(struct device_node *np, int *n > count = of_get_child_count(trips); > if (!count) { > pr_err("No trip point defined\n"); > - ret = -EINVAL; > - goto out_of_node_put; > + return ERR_PTR(-EINVAL); > } > > - tt = kzalloc(sizeof(*tt) * count, GFP_KERNEL); > - if (!tt) { > - ret = -ENOMEM; > - goto out_of_node_put; > - } > - > - *ntrips = count; > + struct thermal_trip *tt __free(kfree) = kzalloc(sizeof(*tt) * count, GFP_KERNEL); Trivial and unrelated, but maybe kcalloc(count, sizeof(tt), GFP_KERNEL); > + if (!tt) > + return ERR_PTR(-ENOMEM); > > count = 0; > for_each_child_of_node_scoped(trips, trip) { > ret = thermal_of_populate_trip(trip, &tt[count++]); > if (ret) > - goto out_kfree; > + return ERR_PTR(ret); > } > > - of_node_put(trips); > + *ntrips = count; > > - return tt; > - > -out_kfree: > - kfree(tt); > - *ntrips = 0; > -out_of_node_put: > - of_node_put(trips); > - > - return ERR_PTR(ret); > + return no_free_ptr(tt); > } > > static struct device_node *of_thermal_zone_find(struct device_node *sensor, int id) >