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 2A57AC433F5 for ; Fri, 15 Apr 2022 12:35:04 +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=01Cz7pBiippnBIjNxOrOsDwnQWIao3gMDt48IHBIoqk=; b=RyMXMXGRGhmBYM oTh3AkYJYTZ1irSdIgEDIJThZLINzsgK+59U2xID00N7Zr7RUregxrhfBHclhUnLAuyRpek8s0q6v xw6vYNDBqfPWucrUrYcsHA+U9Sd5oROSRTYj2HdDT/SNajYkK5xy58hMM4gDg+hWdvM0qRB+7S/uH mqGRazonwRD7Ck5PhMNgQ5GQc3wmyv2WaL3ATVeJi1ljIe/WDxY6z/Tr2i55zhiNQgcKWmxYWZNuE 0TOs6G26lYAFnFgVD3DI16OWBHbdymKgadJWhUJoZmkpEGLEBvkulgpLyhNOWpv7ze3YJe2JXjOzL mgMIZgKDL9R5g/QsHEFQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nfL97-00A1eK-OA; Fri, 15 Apr 2022 12:33:54 +0000 Received: from mail-ej1-x636.google.com ([2a00:1450:4864:20::636]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nfL6D-00A0Bu-4m for linux-arm-kernel@lists.infradead.org; Fri, 15 Apr 2022 12:30:55 +0000 Received: by mail-ej1-x636.google.com with SMTP id bh17so15141774ejb.8 for ; Fri, 15 Apr 2022 05:30:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ky3MoM/ZXCS0RcXaCsseb5+miwfvst1Flp3YDairGIg=; b=VX5z0p2CQATSjZ/cB6fC3h9O4lcoVuaEeHZ5oMj5ah/MF5El83y/G05fbzVfnY4jtV 2jfdW24ABg6n0p6U+h7v6WIwzSt3d7b9iZZfCOVwdb9eRkqsjfUYQfBf0tP9PQhj6xAF ZqzTYECEUx2XXcPHnM08pm1xojDqgZR/wBevx8Sb24MxSgnBtyAz8PoCc58xcG8YAB9G IxK95DPTq6cr0xJ/fmCfUz06QbDZ5Fkpcsn4s7p6FTbWtVO8lIB5Wd8WZQoVWWRcyjNR 0+fySitodpTLLbLvAAk9XfdLW29VtBz3pf+uk388QGLpxd+KwzM5fJkKB+UJDZiq/7vG rzaQ== 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=ky3MoM/ZXCS0RcXaCsseb5+miwfvst1Flp3YDairGIg=; b=2vzraZN34WL/zWBDVzqgLOR/3SD1J5NINiCTfeP9fN4ti808OYz41YJV5tyC/bGfBf +mlqLvfPXQgiJWX/ePGujukbdiy7G1ymxuZvVGPCvAuPsD7CVmz3sL+tyK5ttbwYseHS hYbzNAM8/UTUDlJ0/1PsWNOdn4V6qel9qpYNr62ylwnit9Mi5dsjPta+XAfVo73yDqAe S2OXGX4h89w88j5reQB1D6Rx/t8BoO4R+0xfGZb2gC2kK1NmNqkPVG/NoNos0Jq+KKmX sch8YTQZVjc7c2QsgPOhK3pXxXB/MzGZ0dJiZWrEsiUxgwsfJqvOVmTf9oVPA9v8CGCg vnaA== X-Gm-Message-State: AOAM5322PIzuY11thibnzWfV6YuD8JU40MYeAM1BcTfSejdTbMX6zEyq ieVwuQpc5ioJ8Wd1A52Vgf0= X-Google-Smtp-Source: ABdhPJxVt5dt+TeFnYseiosxE0swakZutRyn/1CBbMxdSXvdp7WSGz2vkXz7SiKCNkURenMOkyTIlg== X-Received: by 2002:a17:907:7f26:b0:6ec:b6a:468 with SMTP id qf38-20020a1709077f2600b006ec0b6a0468mr5278591ejc.661.1650025848973; Fri, 15 Apr 2022 05:30:48 -0700 (PDT) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id bo14-20020a170906d04e00b006ce98d9c3e3sm1649533ejb.194.2022.04.15.05.30.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 05:30:48 -0700 (PDT) From: Jakob Koschel To: "David S. Miller" Cc: Jakub Kicinski , Paolo Abeni , Andrew Lunn , Vivien Didelot , Florian Fainelli , Vladimir Oltean , Lars Povlsen , Steen Hegelund , UNGLinuxDriver@microchip.com, Ariel Elior , Manish Chopra , Edward Cree , Martin Habets , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Jiri Pirko , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Casper Andersson , Bjarni Jonasson , Jakob Koschel , Christophe JAILLET , Arnd Bergmann , Colin Ian King , Eric Dumazet , Xu Wang , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, bpf@vger.kernel.org, Mike Rapoport , "Brian Johannesmeyer" , Cristiano Giuffrida , "Bos, H.J." , Vladimir Oltean Subject: [PATCH net-next v4 03/18] net: dsa: sja1105: reorder sja1105_first_entry_longer_than with memory allocation Date: Fri, 15 Apr 2022 14:29:32 +0200 Message-Id: <20220415122947.2754662-4-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220415122947.2754662-1-jakobkoschel@gmail.com> References: <20220415122947.2754662-1-jakobkoschel@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220415_053053_226060_F82CA020 X-CRM114-Status: GOOD ( 16.14 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Vladimir Oltean sja1105_first_entry_longer_than() does not make use of the full struct sja1105_gate_entry *e, just of e->interval which is set from the passed entry_time. This means that if there is a gate conflict, we have allocated e for nothing, just to free it later. Reorder the memory allocation and the function call, to avoid that and simplify the error unwind path. Signed-off-by: Vladimir Oltean Signed-off-by: Jakob Koschel --- drivers/net/dsa/sja1105/sja1105_vl.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/drivers/net/dsa/sja1105/sja1105_vl.c b/drivers/net/dsa/sja1105/sja1105_vl.c index 369be2ac3587..e5ea8eb9ec4e 100644 --- a/drivers/net/dsa/sja1105/sja1105_vl.c +++ b/drivers/net/dsa/sja1105/sja1105_vl.c @@ -36,7 +36,11 @@ static int sja1105_insert_gate_entry(struct sja1105_gating_config *gating_cfg, { struct sja1105_gate_entry *e; struct list_head *pos; - int rc; + + pos = sja1105_first_entry_longer_than(&gating_cfg->entries, + entry_time, extack); + if (IS_ERR(pos)) + return PTR_ERR(pos); e = kzalloc(sizeof(*e), GFP_KERNEL); if (!e) @@ -45,22 +49,11 @@ static int sja1105_insert_gate_entry(struct sja1105_gating_config *gating_cfg, e->rule = rule; e->gate_state = gate_state; e->interval = entry_time; - - pos = sja1105_first_entry_longer_than(&gating_cfg->entries, - e->interval, extack); - if (IS_ERR(pos)) { - rc = PTR_ERR(pos); - goto err; - } - list_add(&e->list, pos->prev); gating_cfg->num_entries++; return 0; -err: - kfree(e); - return rc; } /* The gate entries contain absolute times in their e->interval field. Convert -- 2.25.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel