Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp1113726rwe; Sat, 27 Aug 2022 00:38:54 -0700 (PDT) X-Google-Smtp-Source: AA6agR7Ymvii5q5NReM+h+dlV1qeMhsW2jFXonWOF0+pz4HuLllm7xCPz6a38Z1kxvQQ2K9LYtn9 X-Received: by 2002:a05:6402:1a36:b0:447:e249:5542 with SMTP id be22-20020a0564021a3600b00447e2495542mr5223838edb.280.1661585933883; Sat, 27 Aug 2022 00:38:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661585933; cv=none; d=google.com; s=arc-20160816; b=reDk70O1WjlcjtpgwIqirOPLYp5feaQX3fWxS7Z0PbPQdzwDRKE8Yapy9dqyzEQqFx M2jLcHev579OcTTmgP7w5E9KOsRQqHelBRCklnrhSYEn/utJaWnysNCcWVmNH0oQ5fdC giwvECdJ/nBeLfc9pf2aWB3VUMfsgqyy/GCjp8uYbZmb8krBYDulSTs54+vR/HedkBXx liMohql8pYfYLC2p0x+pQDCMvjW4dZbbhaTL6fJx+uW92vk8jdlsP/qZ9YG8iOPNeg6B WpbZ8RzIpv3YeCsKtXrmZy2Vi7Lp3T3qsu8uF9owlR9KH4Mx8TzZ1mk1YkgGJLrug92X bSsQ== 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; bh=ndTXdNJhIx6laaOCw/whd5duI49FdCswXqG4EtprUTg=; b=sjUkD6oYyxgjipCiK/RgsDLi44eHDjiHSn9jKPPYYWPuMDs3KugKESgljGW3iYBOiw n5PbBXvRryJboP+1Oy10z0yl1gm1zedAKfXkARp8L34bUdmxjoFGxXc5lukSjOvm8uEd OO8ybqvojqrGnEmSLJ1UBuOjxnkVaAM/Xf0OKiUEapT4TsvcGVsfZG4AQapYwromPmOb J3R/268U3twZlSDTrdLeX4b3Ov7GLVbvHU0d4w9CMR3AG0mdu5FsCByh0pT2laUSVpaD bzm+aCq7y0VNVkIC9XTD5q8p+GubQ1CCx3CjITKF6APa0/gU6qyD3ATSMopw2zQU9EWN iSnQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cw8-20020a170906478800b0074156b2af5fsi140527ejc.829.2022.08.27.00.38.26; Sat, 27 Aug 2022 00:38:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232947AbiH0HUa (ORCPT + 99 others); Sat, 27 Aug 2022 03:20:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232449AbiH0HUX (ORCPT ); Sat, 27 Aug 2022 03:20:23 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01B477C74B; Sat, 27 Aug 2022 00:20:21 -0700 (PDT) Received: from canpemm500006.china.huawei.com (unknown [172.30.72.55]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4MF7L60z9mz1N7Gs; Sat, 27 Aug 2022 15:16:46 +0800 (CST) Received: from ubuntu-82.huawei.com (10.175.104.82) by canpemm500006.china.huawei.com (7.192.105.130) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Sat, 27 Aug 2022 15:20:19 +0800 From: Ziyang Xuan To: , , , CC: , , , , Subject: [PATCH net-next 2/2] can: raw: use guard clause to optimize nesting in raw_rcv() Date: Sat, 27 Aug 2022 15:20:11 +0800 Message-ID: <0170ad1f07dbe838965df4274fce950980fa9d1f.1661584485.git.william.xuanziyang@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.104.82] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To canpemm500006.china.huawei.com (7.192.105.130) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 We can use guard clause to optimize nesting codes like if (condition) { ... } else { return; } in raw_rcv(); Signed-off-by: Ziyang Xuan --- net/can/raw.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/net/can/raw.c b/net/can/raw.c index 9ae7c4206b9a..e7dfa3584e29 100644 --- a/net/can/raw.c +++ b/net/can/raw.c @@ -136,14 +136,13 @@ static void raw_rcv(struct sk_buff *oskb, void *data) /* eliminate multiple filter matches for the same skb */ if (this_cpu_ptr(ro->uniq)->skb == oskb && this_cpu_ptr(ro->uniq)->skbcnt == can_skb_prv(oskb)->skbcnt) { - if (ro->join_filters) { - this_cpu_inc(ro->uniq->join_rx_count); - /* drop frame until all enabled filters matched */ - if (this_cpu_ptr(ro->uniq)->join_rx_count < ro->count) - return; - } else { + if (!ro->join_filters) + return; + + this_cpu_inc(ro->uniq->join_rx_count); + /* drop frame until all enabled filters matched */ + if (this_cpu_ptr(ro->uniq)->join_rx_count < ro->count) return; - } } else { this_cpu_ptr(ro->uniq)->skb = oskb; this_cpu_ptr(ro->uniq)->skbcnt = can_skb_prv(oskb)->skbcnt; -- 2.25.1