Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp1022463ybg; Mon, 1 Jun 2020 22:28:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxrTZOpuH2eGL82dlgPba0oyuyTOlVkJknjSemtb0ryfwDxkAaRLwr7SOLttWrJDEZPxbit X-Received: by 2002:a17:906:49ca:: with SMTP id w10mr23090023ejv.31.1591075719724; Mon, 01 Jun 2020 22:28:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591075719; cv=none; d=google.com; s=arc-20160816; b=XCPSliWPfmA78Xti1t+u6Ihvgeplw9Yehoe0UZnwiAR6y2erNCep1xWXxTJYWgeLCA QvjMxoqEhVdcVTviF/Y7t62ikPO9RASMcq0ftxYewW94VZei3uG7tUcTxHJeDbkL5rFQ CPKwVOm5SqiHDA/eUsl+cwusnlRlGxqjQ29Z1er52IIG/XzQM5KgPhzmYEKeG69Z/k9W b9EyUMQDI/woKpDFtIhrb4YG2Kl0v3OyqIJg5F00I1/cIV7FtZQy4/Nwe5wrbj9X2K1M /4TgqLqeDAJQvk1f+SvJ05kGmvoJlvJOMQCTm2ZNttrd9xevN1MJ/FT7eKql4QcNFHGr tqdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:to:from; bh=59W1mU/bQcyzFRGEkIoy3tsoofamzbdt7B1l1b9v8NA=; b=CYzepd9mT3bgXP2jo90G+/3pVrWf8dDlj/taelyPgDuwB0TK2IbJZYkMmtnE9oNiwv SG6D/FexnTwZTfb0epB/gInt7bcnh0cdEHVt/WBwx+BKO2Amz9QIvZqF+EbkXdEixKNR 9V87lh1fEMxhtY+4J6zeFIcKfNs12jNWdGjpxrRbOrcUpW1vHWmQJTsjT0BRDTmkKAM/ 0ZGcU2SANqj265aZhwKVb4kflJZBK7Jido67pj2up+vxLd16ZEkOISPMPiymSAjf23CU LZCCyJTpYsSmmYpmJQwBJvHSW+fh4vTEanct1IYE6xzIH2iaRknAwh3fC/luvFFIHto0 m3dg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gh6si871571ejb.689.2020.06.01.22.28.16; Mon, 01 Jun 2020 22:28:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727932AbgFBFYS (ORCPT + 99 others); Tue, 2 Jun 2020 01:24:18 -0400 Received: from inva021.nxp.com ([92.121.34.21]:40846 "EHLO inva021.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726964AbgFBFYR (ORCPT ); Tue, 2 Jun 2020 01:24:17 -0400 Received: from inva021.nxp.com (localhost [127.0.0.1]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id B045320094A; Tue, 2 Jun 2020 07:24:14 +0200 (CEST) Received: from invc005.ap-rdc01.nxp.com (invc005.ap-rdc01.nxp.com [165.114.16.14]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 2B23C20094E; Tue, 2 Jun 2020 07:24:05 +0200 (CEST) Received: from localhost.localdomain (mega.ap.freescale.net [10.192.208.232]) by invc005.ap-rdc01.nxp.com (Postfix) with ESMTP id 274A940323; Tue, 2 Jun 2020 13:23:53 +0800 (SGT) From: Xiaoliang Yang To: xiaoliang.yang_1@nxp.com, po.liu@nxp.com, claudiu.manoil@nxp.com, alexandru.marginean@nxp.com, vladimir.oltean@nxp.com, leoyang.li@nxp.com, mingkai.hu@nxp.com, andrew@lunn.ch, f.fainelli@gmail.com, vivien.didelot@gmail.com, davem@davemloft.net, jiri@resnulli.us, idosch@idosch.org, kuba@kernel.org, vinicius.gomes@intel.com, nikolay@cumulusnetworks.com, roopa@cumulusnetworks.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, horatiu.vultur@microchip.com, alexandre.belloni@bootlin.com, allan.nielsen@microchip.com, joergen.andreasen@microchip.com, UNGLinuxDriver@microchip.com, linux-devel@linux.nxdi.nxp.com Subject: [PATCH v2 net-next 08/10] net: ocelot: return error if rule is not found Date: Tue, 2 Jun 2020 13:18:26 +0800 Message-Id: <20200602051828.5734-9-xiaoliang.yang_1@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200602051828.5734-1-xiaoliang.yang_1@nxp.com> References: <20200602051828.5734-1-xiaoliang.yang_1@nxp.com> X-Virus-Scanned: ClamAV using ClamSMTP Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return error if rule is not found in rule list to avoid Kernel panic. Signed-off-by: Xiaoliang Yang --- drivers/net/ethernet/mscc/ocelot_ace.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/mscc/ocelot_ace.c b/drivers/net/ethernet/mscc/ocelot_ace.c index bf2b7a03c832..2ba2859fa2cd 100644 --- a/drivers/net/ethernet/mscc/ocelot_ace.c +++ b/drivers/net/ethernet/mscc/ocelot_ace.c @@ -982,9 +982,9 @@ static int ocelot_ace_rule_get_index_id(struct ocelot_acl_block *block, list_for_each_entry(tmp, &block->rules, list) { ++index; if (rule->id == tmp->id) - break; + return index; } - return index; + return -ENOENT; } static struct ocelot_ace_rule* @@ -1197,6 +1197,8 @@ int ocelot_ace_rule_offload_del(struct ocelot *ocelot, int block_id, /* Gets index of the rule */ index = ocelot_ace_rule_get_index_id(block, rule); + if (index < 0) + return -ENOENT; /* Delete rule */ ocelot_ace_rule_del(ocelot, block, rule); @@ -1221,6 +1223,9 @@ int ocelot_ace_rule_stats_update(struct ocelot *ocelot, int block_id, int index; index = ocelot_ace_rule_get_index_id(block, rule); + if (index < 0) + return -ENOENT; + vcap_entry_get(ocelot, rule, index, block_id); /* After we get the result we need to clear the counters */ -- 2.17.1