Received: by 2002:a19:f614:0:0:0:0:0 with SMTP id x20csp56733lfe; Fri, 15 Apr 2022 19:18:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzPq4/4h8jMHfOpIj6RyMTuw0rZ+H/NvXC+OfSO5Wl3IcFn0gi3fW+MbhD0sMOGbBXsT9N/ X-Received: by 2002:a17:903:11cc:b0:151:71e4:dadc with SMTP id q12-20020a17090311cc00b0015171e4dadcmr1498786plh.78.1650075487687; Fri, 15 Apr 2022 19:18:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650075487; cv=none; d=google.com; s=arc-20160816; b=SukWXjoqSTW0KMJcQMdjCfyli/c/lWzKN4rpfhBOlQZcAU9ozQ+QAR2viK+LNUJUbG 4CiNQK4cg6NHoQhto5J7zF1M6a97M9RyiPwZrbOqjMVWuQvxl69JcW32+hYr1QA1CDjc gHJNQYm6kv44QrF3KzgaiWAoUq9nLgOrlwMMff9ENl9xD6lOV4BI4GMzWtrspdNHQtto JEVzzv0qoRxXPKbwh3vauM7WSwCT6Da1PA1ThKRHTg0jr0FGbbj/aOiZNpBCzLlO0USO qbIwRVgGvk9nzpnQtVDGv581c0m2hW+bph9Kz3QGyg3sr5WC/HGx26ZMuPA9pGnYjyk9 sfGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ky3MoM/ZXCS0RcXaCsseb5+miwfvst1Flp3YDairGIg=; b=hHLS9snbZD63XvrE6rd2c1lEm3sBR58D4VRXTWd41jmGjoSmOUif1oelq0xPnDyvFw ggUtnxoxC+XJqdIw28MGfwnWzpyNbpNlD0/mTuKXhbQ+pEPAsgPWWr/+JC8vzCQrDB4U J+U+hvAMX5/j6LW6nT0ZccbTrA/lWNFliQF+IZkuIL+992f4ccyAUl/KMv/lCWd57bl5 tcTwW2pg1Un89xkcJ4VAPaArGS3fnZ7Da5Fr7cjp58wvCyYLHLb5MfGdz8gFX/8JJzRV vC5QwwbQQy49860TtCz2DmmNF1GvQFPVltWVat8O6xHW60J0iHiC/Tlr2XG5cXNv8OPp 6Ftg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=VX5z0p2C; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id c4-20020a056a000ac400b00505d99afd25si3140499pfl.29.2022.04.15.19.18.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 19:18:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=VX5z0p2C; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1321C150429; Fri, 15 Apr 2022 18:33:30 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353575AbiDOMe4 (ORCPT + 99 others); Fri, 15 Apr 2022 08:34:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353812AbiDOMdS (ORCPT ); Fri, 15 Apr 2022 08:33:18 -0400 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C285329A7; Fri, 15 Apr 2022 05:30:50 -0700 (PDT) Received: by mail-ej1-x633.google.com with SMTP id p15so15141678ejc.7; 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=a/sA7uWE7r+FdQiVjUkb4IU9Y2Br6DMDFLbgykV/s2Cmq4zqTBvIdwkNJdfmM2G4IY nDTfSGuaSZpIt+aSjgUBsCLCmmyS3xAP6cuSvaPsaWdBngKfyWJhW1ARiiu0sIG2bhvD Q6/oWn8w7NnjH5UXbIGl2RfH3M5tKjBYmklaxChLPftaOQa0LnGuX+bIfoQnFct4/3KD eJBV7cysilXGAJyVRaObRyeZekUzkX1tEA8ElcFFIDnMIka7W/yZfHxQlObgUTpacLtM h8hyA0v89wV56C/TvO/hXJ8D4j9VByH+pNSvaY7ckhXEw2dYfrTMe3IG9um0LseN19Mx /iAg== X-Gm-Message-State: AOAM531W9x/+jA/OhwCK+7zhdasdUBpUZEnJgReds63MXBcqk6yMstqL 3T/UibKCSTPBaZmrYl6QCb0= 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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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