Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp2187523lqe; Tue, 9 Apr 2024 12:00:20 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU20owujg8C8dYcI08d2G97yisu6vPEBNYaqNW09JWax18VUsew1irZGVJiWyPJxNBisXatxajgc46tcup4/7g70JcFJj/lIVhP37md2Q== X-Google-Smtp-Source: AGHT+IG4o9/bONckJqujS4P6p7WXlr7QFp1cpBGyylt5DHtw/wjtC4VmCMNGmZxl41xyDu+cvy5j X-Received: by 2002:a05:6a21:3405:b0:1a9:499c:5779 with SMTP id yn5-20020a056a21340500b001a9499c5779mr734540pzb.30.1712689219873; Tue, 09 Apr 2024 12:00:19 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712689219; cv=pass; d=google.com; s=arc-20160816; b=ieNS1isA0oV25jYyVxwdA4/w2vUc9SRDJl024+l8gmSIlqO3S+6+IrL1baHJ3zyrtq d+tmrR0fCLOZkawcNvpweo9LxUPBAryFE8vJQ6bs+D7klfYAxJLEZTcog0/Fs7Lw8Zfp CE2J6v+cnQc4UrW8cDOZaSw49hRnw1ar3aC0qhgkhehHySWpopcdCZmGEuEm/FwOTVS0 PWDl96AqumrsuS2VqT+5DBkivm31umt9/DSPZwDKr2v5LzYB9vDbZvX8d7seSwfGc1Dx K1z1ldBbgpoNpfdwqupfxL2bUz2f1ukdYeoyVU78xNd41wBHcyc8x6QL661vfhLiXESb c02Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=bm2Otp3QAAtv+TMEe21kLt4qeTVDVNoHSYJ7X0gudhQ=; fh=HaAbeQxkuAwJ2ivQh/Pn6sGMetfCZEzdA+gA1Ssze7o=; b=fSDLFQLYpzYORusj7F9IkriHbaxgzq2OE+xIYf01iYWxNbrOEkxeIFA6+bOFvZYUro 2Y1VRTjtSPzcSoLkcRqJiujtU0Ib7IDlq7QO2f1k54J4QMjDyQkoQa7LMiZygyj4ipgi CGL1MioUvJwCkdNBKafgARrWehh+epW2zxl6X/h3GUeqCAIih/Kb8seUZmGN4ghuzMgv Mh5+i0FYx58BtaQ2K+uloHaOBgDIg1AbkMGqM1gQQNgq4crcuWP8vViCPPODgLRn5WFM JGkQvoEL1QchdtV+5BhAZADFwnrsR473E0wcCp7oGZ/gTfoBSyG75qfAs+Jxa2nwhh54 NdrQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=r4hGjxCj; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-137489-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-137489-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id ja14-20020a170902efce00b001e2a43cd54dsi8822166plb.192.2024.04.09.12.00.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 12:00:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-137489-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=r4hGjxCj; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-137489-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-137489-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 01DD0B22276 for ; Tue, 9 Apr 2024 19:00:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C334B157493; Tue, 9 Apr 2024 18:59:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="r4hGjxCj" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EA499157478; Tue, 9 Apr 2024 18:59:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712689191; cv=none; b=fS12j8iCEZCyxrWisEXj50XN2d+7W+yUkpzHYgbsDNjpEey5xrBBS0bPALbcmu9eiARd4IGOWi8i5eCChEga4K2hHetI4ZVWH2JJvHR83JJ2ZRlvNXyuYpRc4zwHCbD62Yc2wuz81wAaAo155B5lt1QmXygyQpcX68ZrCPsO1Qg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712689191; c=relaxed/simple; bh=rQ1wN85KvyDr48E/qDDapLu5pJUhnzdbM/cwNfrXARI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=QDoOCziZ2jP08DgXKv33I4r9Czf39taq7Yldtwb1WiDg+k14NK6tWNI8BF3iLNQp5vLJ4p879r9OQuKvlFhpZ5xC97LqDv9NTctmFOIp5kDmmrz1EoovKfDFvWoZZVBrHqmwNG1TvrFXTkYhc+hRK5GO8gZPsVp0p58zY/12vKM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=r4hGjxCj; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 45AF6C433C7; Tue, 9 Apr 2024 18:59:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712689190; bh=rQ1wN85KvyDr48E/qDDapLu5pJUhnzdbM/cwNfrXARI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=r4hGjxCjpDkwKcy7c8SOBbtbnq6r3tyJFqmodY4ysuckS+GpEJyzaVL7r1LHXZesU QLDZFtSc02R0rhF+E6oIVPCmpNiv06hkuIbtdJtSOkCXazDdaA00ICrpOGQT5j0Q/t /L8VHrltviHsHAgGniO2L+40V3MouHADODO3iH8PioUIQKstIW2SdvgDBb73uzeiN7 IMopX8BVnFie0GnerpxMcgnfHWMk0fdt2QHMnn+x4/wWeICN9TbaMACCL3w7dWKj75 UzfEO2cgMKJHWw1s1uhoWfbM17QpV3zxrrl1VyeHpEC27gcr7Tm6cQTUp0UNEf+Upj q0DpNp3gWb9dQ== From: Rob Herring Date: Tue, 09 Apr 2024 13:59:39 -0500 Subject: [PATCH v2 1/3] of: Add a helper to free property struct Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240409-dt-cleanup-free-v2-1-5b419a4af38d@kernel.org> References: <20240409-dt-cleanup-free-v2-0-5b419a4af38d@kernel.org> In-Reply-To: <20240409-dt-cleanup-free-v2-0-5b419a4af38d@kernel.org> To: Saravana Kannan Cc: Jonathan Cameron , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Jonathan Cameron X-Mailer: b4 0.13-dev Freeing a property struct is 3 kfree()'s which is duplicated in multiple spots. Add a helper, __of_prop_free(), and replace all the open coded cases in the DT code. Reviewed-by: Saravana Kannan Reviewed-by: Jonathan Cameron Signed-off-by: Rob Herring --- drivers/of/dynamic.c | 26 ++++++++++++-------------- drivers/of/of_private.h | 1 + drivers/of/overlay.c | 11 +++-------- drivers/of/unittest.c | 12 +++--------- 4 files changed, 19 insertions(+), 31 deletions(-) diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c index 3bf27052832f..af7c57a7a25d 100644 --- a/drivers/of/dynamic.c +++ b/drivers/of/dynamic.c @@ -305,15 +305,20 @@ int of_detach_node(struct device_node *np) } EXPORT_SYMBOL_GPL(of_detach_node); +void __of_prop_free(struct property *prop) +{ + kfree(prop->name); + kfree(prop->value); + kfree(prop); +} + static void property_list_free(struct property *prop_list) { struct property *prop, *next; for (prop = prop_list; prop != NULL; prop = next) { next = prop->next; - kfree(prop->name); - kfree(prop->value); - kfree(prop); + __of_prop_free(prop); } } @@ -426,9 +431,7 @@ struct property *__of_prop_dup(const struct property *prop, gfp_t allocflags) return new; err_free: - kfree(new->name); - kfree(new->value); - kfree(new); + __of_prop_free(new); return NULL; } @@ -470,9 +473,7 @@ struct device_node *__of_node_dup(const struct device_node *np, if (!new_pp) goto err_prop; if (__of_add_property(node, new_pp)) { - kfree(new_pp->name); - kfree(new_pp->value); - kfree(new_pp); + __of_prop_free(new_pp); goto err_prop; } } @@ -921,11 +922,8 @@ static int of_changeset_add_prop_helper(struct of_changeset *ocs, return -ENOMEM; ret = of_changeset_add_property(ocs, np, new_pp); - if (ret) { - kfree(new_pp->name); - kfree(new_pp->value); - kfree(new_pp); - } + if (ret) + __of_prop_free(new_pp); return ret; } diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h index 485483524b7f..94fc0aa07af9 100644 --- a/drivers/of/of_private.h +++ b/drivers/of/of_private.h @@ -123,6 +123,7 @@ extern void *__unflatten_device_tree(const void *blob, * own the devtree lock or work on detached trees only. */ struct property *__of_prop_dup(const struct property *prop, gfp_t allocflags); +void __of_prop_free(struct property *prop); struct device_node *__of_node_dup(const struct device_node *np, const char *full_name); diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c index 2ae7e9d24a64..4d861a75d694 100644 --- a/drivers/of/overlay.c +++ b/drivers/of/overlay.c @@ -262,9 +262,7 @@ static struct property *dup_and_fixup_symbol_prop( return new_prop; err_free_new_prop: - kfree(new_prop->name); - kfree(new_prop->value); - kfree(new_prop); + __of_prop_free(new_prop); err_free_target_path: kfree(target_path); @@ -361,11 +359,8 @@ static int add_changeset_property(struct overlay_changeset *ovcs, pr_err("WARNING: memory leak will occur if overlay removed, property: %pOF/%s\n", target->np, new_prop->name); - if (ret) { - kfree(new_prop->name); - kfree(new_prop->value); - kfree(new_prop); - } + if (ret) + __of_prop_free(new_prop); return ret; } diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index 6b5c36b6a758..a8c01c953a29 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -795,15 +795,11 @@ static void __init of_unittest_property_copy(void) new = __of_prop_dup(&p1, GFP_KERNEL); unittest(new && propcmp(&p1, new), "empty property didn't copy correctly\n"); - kfree(new->value); - kfree(new->name); - kfree(new); + __of_prop_free(new); new = __of_prop_dup(&p2, GFP_KERNEL); unittest(new && propcmp(&p2, new), "non-empty property didn't copy correctly\n"); - kfree(new->value); - kfree(new->name); - kfree(new); + __of_prop_free(new); #endif } @@ -3718,9 +3714,7 @@ static __init void of_unittest_overlay_high_level(void) goto err_unlock; } if (__of_add_property(of_symbols, new_prop)) { - kfree(new_prop->name); - kfree(new_prop->value); - kfree(new_prop); + __of_prop_free(new_prop); /* "name" auto-generated by unflatten */ if (!strcmp(prop->name, "name")) continue; -- 2.43.0