From patchwork Fri Mar 19 04:29:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 404734 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp1053366jai; Thu, 18 Mar 2021 21:30:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzGYsAYHE7P9+ZHs7CNfhW7WOgP8C8PTZt8paxU+ueltRA3Sa+YnW2Muh9nxyVRM7DFlHr5 X-Received: by 2002:a17:906:9501:: with SMTP id u1mr2222593ejx.324.1616128216497; Thu, 18 Mar 2021 21:30:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616128216; cv=none; d=google.com; s=arc-20160816; b=znm3dH2EYWiKOUuqUIpy/wHxAZy31X53O1HYhIgHzWAWQZMK1euamQJ/t8kEpbtNB1 MUsfqEPqs6bHqa3yHM+0H+/fxhYnnCxOFTp+VJUNFPcArY3wZIT6kEUJ/LavMcU8k4q8 fJKRIWM/y1Jo4EwXERV/MzM7NUx1dzQWdMoCM4+YBuJp/yvoGValuAKvhx7+pEMMRLtG TuwwmD0JHx3yxgNQtLN2YxJn+Z5Z42KndNqEeaoCIGcOJZjp5A1WRF0u21icSsQJpeqz x7XG2gwrGynGHX88KkuyPkVn9frqFvVzMoQD6ZNH6HIixNUcBBtPkzpS2l5es3eEtUQd CRXA== 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=Y0jgz//zVEbNql9HK61bKjTuk8XcYuXVt9tdgPActZw=; b=g8ZqjtCLeR9bNkNYxIv8TEuMVzGOGFRYDZ9nUglv/tPUOa7crW2yzvBV8ZeOWR+Nxe lYvnGSIGUN4qcVPGZa3ds8yLpNWLr7GrwlK4NT7inPPerIjJ++tO/iRHgJUsJOaR1f6x vUZVit1l39Zn2HJlRwnj/LJclpQLPe5E/ykEONVrx37b4QqOifiZ82kdoPsCQ8dEFEy5 qX0qLIwH8+Pl7Oxsuk6Jul3YnqcXPorHe6wzQbMpaqfwPtkC3hCPCuTYBRk/bOkKqH3U a1SV9JutLiC2igBePIthJ6v49uhy+64EzMugoWRfe7BUKlsnvoGTdnEL1rNMBehzfh9m 6j+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BOWuRozL; spf=pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h20si3135507edq.97.2021.03.18.21.30.16; Thu, 18 Mar 2021 21:30:16 -0700 (PDT) Received-SPF: pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BOWuRozL; spf=pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233737AbhCSE3p (ORCPT + 8 others); Fri, 19 Mar 2021 00:29:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233734AbhCSE32 (ORCPT ); Fri, 19 Mar 2021 00:29:28 -0400 Received: from mail-io1-xd32.google.com (mail-io1-xd32.google.com [IPv6:2607:f8b0:4864:20::d32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8CD72C06174A for ; Thu, 18 Mar 2021 21:29:28 -0700 (PDT) Received: by mail-io1-xd32.google.com with SMTP id v17so4737316iot.6 for ; Thu, 18 Mar 2021 21:29:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Y0jgz//zVEbNql9HK61bKjTuk8XcYuXVt9tdgPActZw=; b=BOWuRozLgqzrcjQClsoI5cN9tLYe2V9Zs90rup1kKI4tRLIN8S2j4AVpgIWlpCK/p8 tPTTyQGQMshP+KNH5lEbUvETtHeqaTS5ptHrfxY4FuAXSHLA2tIUj/9MxNdmv+VQkFeI qqULh1NeITSaTzb2dtUa66bbSaTv+EdIivhV6KlNlmEvgvVSnppGW70jCxuspiV/jnkf nM6v0GKM1xNE0qc9UFHgKiF3C9zxEl+kw9KbAEhHlcSVe7MK484LmztO6XXPGTenPS+c Klkt4VNqCaV4VzVwWg+D3fXIpqGpKRQGnUryVIb5m1JmaReL1Q6S37ogP4e+O0Z2E59d Duow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Y0jgz//zVEbNql9HK61bKjTuk8XcYuXVt9tdgPActZw=; b=hljBqbwrkk1mVf5NsUGeehpztfDy6yfOCda4mOLDMjCEFhEq1n15LWoh70aoP8DhOa JpzryHBS4yOgOs08OFH6BbHllMWJW9cesz2pl+hWaRiNoCcYIRKmhnJEi02QzVAd42Nz 8c4NA+T35OuwdZn3rwshuVSOZNOocUDf5rEnYzosxhAoRi3tQzh6Z3I39lcMzctLPbOn QXOj1LggRFVTtNTH/XFqWbH8n6UbotFFj5Zv5KUEEM2+p/SnSUYynYll/vrw0atMKemF u3zi+FxDX8v13TtpIIyLGVqUcnSt7qXPsnHYoZTRmphe477mNnOZ1eJxYFISG3Be9uH2 0Jgg== X-Gm-Message-State: AOAM530DFcQ3xlhOwVato9+gTFVSNvamdwtKPJP9f1RFsNJe0hV8TI2r nKNYOz2WtitNN4DwYCkJ7Ns41Q== X-Received: by 2002:a5d:9610:: with SMTP id w16mr1433166iol.167.1616128167997; Thu, 18 Mar 2021 21:29:27 -0700 (PDT) Received: from localhost.localdomain (c-73-185-129-58.hsd1.mn.comcast.net. [73.185.129.58]) by smtp.gmail.com with ESMTPSA id k3sm1985940ioj.35.2021.03.18.21.29.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Mar 2021 21:29:27 -0700 (PDT) From: Alex Elder To: davem@davemloft.net, kuba@kernel.org Cc: bjorn.andersson@linaro.org, evgreen@chromium.org, cpratapa@codeaurora.org, elder@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next 1/4] net: ipa: fix init header command validation Date: Thu, 18 Mar 2021 23:29:20 -0500 Message-Id: <20210319042923.1584593-2-elder@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210319042923.1584593-1-elder@linaro.org> References: <20210319042923.1584593-1-elder@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org We use ipa_cmd_header_valid() to ensure certain values we will program into hardware are within range, well in advance of when we actually program them. This way we avoid having to check for errors when we actually program the hardware. Unfortunately the dev_err() call for a bad offset value does not supply the arguments to match the format specifiers properly. Fix this. There was also supposed to be a check to ensure the size to be programmed fits in the field that holds it. Add this missing check. Rearrange the way we ensure the header table fits in overall IPA memory range. Signed-off-by: Alex Elder --- drivers/net/ipa/ipa_cmd.c | 49 +++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 17 deletions(-) -- 2.27.0 diff --git a/drivers/net/ipa/ipa_cmd.c b/drivers/net/ipa/ipa_cmd.c index 35e35852c25c5..b40f031a905a7 100644 --- a/drivers/net/ipa/ipa_cmd.c +++ b/drivers/net/ipa/ipa_cmd.c @@ -175,21 +175,23 @@ bool ipa_cmd_table_valid(struct ipa *ipa, const struct ipa_mem *mem, : field_max(IP_FLTRT_FLAGS_NHASH_ADDR_FMASK); if (mem->offset > offset_max || ipa->mem_offset > offset_max - mem->offset) { - dev_err(dev, "IPv%c %s%s table region offset too large " - "(0x%04x + 0x%04x > 0x%04x)\n", - ipv6 ? '6' : '4', hashed ? "hashed " : "", - route ? "route" : "filter", - ipa->mem_offset, mem->offset, offset_max); + dev_err(dev, "IPv%c %s%s table region offset too large\n", + ipv6 ? '6' : '4', hashed ? "hashed " : "", + route ? "route" : "filter"); + dev_err(dev, " (0x%04x + 0x%04x > 0x%04x)\n", + ipa->mem_offset, mem->offset, offset_max); + return false; } if (mem->offset > ipa->mem_size || mem->size > ipa->mem_size - mem->offset) { - dev_err(dev, "IPv%c %s%s table region out of range " - "(0x%04x + 0x%04x > 0x%04x)\n", - ipv6 ? '6' : '4', hashed ? "hashed " : "", - route ? "route" : "filter", - mem->offset, mem->size, ipa->mem_size); + dev_err(dev, "IPv%c %s%s table region out of range\n", + ipv6 ? '6' : '4', hashed ? "hashed " : "", + route ? "route" : "filter"); + dev_err(dev, " (0x%04x + 0x%04x > 0x%04x)\n", + mem->offset, mem->size, ipa->mem_size); + return false; } @@ -205,22 +207,35 @@ static bool ipa_cmd_header_valid(struct ipa *ipa) u32 size_max; u32 size; + /* In ipa_cmd_hdr_init_local_add() we record the offset and size + * of the header table memory area. Make sure the offset and size + * fit in the fields that need to hold them, and that the entire + * range is within the overall IPA memory range. + */ offset_max = field_max(HDR_INIT_LOCAL_FLAGS_HDR_ADDR_FMASK); if (mem->offset > offset_max || ipa->mem_offset > offset_max - mem->offset) { - dev_err(dev, "header table region offset too large " - "(0x%04x + 0x%04x > 0x%04x)\n", - ipa->mem_offset + mem->offset, offset_max); + dev_err(dev, "header table region offset too large\n"); + dev_err(dev, " (0x%04x + 0x%04x > 0x%04x)\n", + ipa->mem_offset, mem->offset, offset_max); + return false; } size_max = field_max(HDR_INIT_LOCAL_FLAGS_TABLE_SIZE_FMASK); size = ipa->mem[IPA_MEM_MODEM_HEADER].size; size += ipa->mem[IPA_MEM_AP_HEADER].size; - if (mem->offset > ipa->mem_size || size > ipa->mem_size - mem->offset) { - dev_err(dev, "header table region out of range " - "(0x%04x + 0x%04x > 0x%04x)\n", - mem->offset, size, ipa->mem_size); + if (size > size_max) { + dev_err(dev, "header table region too large\n"); + dev_err(dev, " (0x%04x > 0x%04x)\n", size, size_max); + + return false; + } + if (size > ipa->mem_size || mem->offset > ipa->mem_size - size) { + dev_err(dev, "header table region out of range\n"); + dev_err(dev, " (0x%04x + 0x%04x > 0x%04x)\n", + mem->offset, size, ipa->mem_size); + return false; } From patchwork Fri Mar 19 04:29:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 404733 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp1053358jai; Thu, 18 Mar 2021 21:30:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxW23c4BoH0ROIZy4LtQnSkdWHcYN940AXoYlOw7O8avE4jMhaQIZ8+ndQm66kHIMGN7qpM X-Received: by 2002:aa7:d4ca:: with SMTP id t10mr7319236edr.388.1616128215727; Thu, 18 Mar 2021 21:30:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616128215; cv=none; d=google.com; s=arc-20160816; b=iZLMD8EyC5BtUODEX0tuEip3Gl7IuADPRTkEEYtsYlQUyeATncrICpProR175vxLXu +LKafLQlhn/fN6O0/peLWhXcoz5+bkyvSmxcW2MZCTxOEWyeCdACg5exZSlgIc5pj83H CZ4LqNy5Q6a4By/sYye15rmQfr6UhRwVUFw5l2GxdfnaHYg8cE3ZXx+BEBVlH1nHAgmF EF1rh5IhhMREUI3smVhW36cmTK4cV/dT0vntzR9LJvxANc6Wxlj8k8BeaGSU9wB4xrZ7 2cWhIa3cbrfRlmFuz/ly2iBu3arYF4t/T0YH7FLEepspAxNeNkFPLToqCE3N3XTLbtfW KkrQ== 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=vzA9KnL8HeyQyzi363rK2CanaeOSNA8szEwKhfqGIPA=; b=h2EkIriKn/K1MPaRcxsmi4KZE4SzqjPpa/SnwmG7JHNCUPSOZEBcBasG1NLGeDcyzk pMwkLWI5X96uHVcqqzxKaNgCSl6iIYOkw6seT0WhKifHBpmYAgJZWHcDBQMvogxVWz45 jGnXIRCJMeSrD14+gJndgyVd2pSNLtG62M79cqneKuHHS3yvj9X1OvUSgvdJoZKSo272 VZklNNJ86pLmFSsKn+9SOBh3gcz5a3fBiuSRkAc7QKAs4f3Tu7pBLKcnC/DIaX0m1bK4 lha1GKrHbZr/A3xXAfigPEIUGCZ2N/xlkpfrNXXLD1e803cQAEu8rHIGjCtq8fkgIbjr u55g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wUt8jzPb; spf=pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h20si3135507edq.97.2021.03.18.21.30.15; Thu, 18 Mar 2021 21:30:15 -0700 (PDT) Received-SPF: pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wUt8jzPb; spf=pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233768AbhCSE3o (ORCPT + 8 others); Fri, 19 Mar 2021 00:29:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233740AbhCSE33 (ORCPT ); Fri, 19 Mar 2021 00:29:29 -0400 Received: from mail-il1-x12c.google.com (mail-il1-x12c.google.com [IPv6:2607:f8b0:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E8A3C06174A for ; Thu, 18 Mar 2021 21:29:29 -0700 (PDT) Received: by mail-il1-x12c.google.com with SMTP id c17so6929931ilj.7 for ; Thu, 18 Mar 2021 21:29:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vzA9KnL8HeyQyzi363rK2CanaeOSNA8szEwKhfqGIPA=; b=wUt8jzPbXkSc951YvWneKW4DfFd3WoAH6DWlY6sQmfEQzu04UkX2o2f2I+af6TdRsx AlziwmojIDrfcDAXf0rrhTmFGLaix8Jfbhp6H/fwGGL+s59NgMoM2lMQgBrMuHZDtrWu RCdqx9S9Jmo1ogdXJim7zIIJPbT2zRzjj+ZJgOQNp0/BNYG1bq9/nXc371NpT13raAfc MuOoi7W1hxdqcOf1XcACsQFx5QDxu9HNaG4iE3pO03ij5pxSjX4evNVxunaNgxa9Vew1 dBtVR6p6j0kQY/pQL7MjKIQJKcieM/v4kZxZzeDRelsKdEskcFwJkaK0NLWqJEz27RoH v2XQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vzA9KnL8HeyQyzi363rK2CanaeOSNA8szEwKhfqGIPA=; b=MMgOON1F7JDc2WOLFPigKRk0zlf5ZzqQoX//CT0VEkJeALKnJteUsA/+nurs++swfK OMywQ+PdFC9IzCWQErEvYy7eofh5VSBqfRfifLJ1aepAhBdB/TYxvA3OlNrk3yQROsrR 0ETJwfrg5vU+TUGshfNrU79NtMCuNEkl5A4wX1TL/f63DMc0lQJN/JauL+RjYXU1TEIe lAv+/aDz9wOS1WvT4DJTXbxeiYTcEMXbU6FtQPVJ268Byy/DRZkNdCzHPLNH/LU0vqdu NtbE094WQZBSWUYBTmLQu6nGK6TYsxiKBfG4yhkAUBYupzcF4vIKZTG2oBloCJupnyjk Xbsg== X-Gm-Message-State: AOAM533uuD9dTA5x5lMulYWz9WnRqED93tg5JpI40bTQ8VhrLGput5SN KD/dbgNyI6iAYVhPfZp931IlEA== X-Received: by 2002:a05:6e02:1a6d:: with SMTP id w13mr1378798ilv.253.1616128168896; Thu, 18 Mar 2021 21:29:28 -0700 (PDT) Received: from localhost.localdomain (c-73-185-129-58.hsd1.mn.comcast.net. [73.185.129.58]) by smtp.gmail.com with ESMTPSA id k3sm1985940ioj.35.2021.03.18.21.29.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Mar 2021 21:29:28 -0700 (PDT) From: Alex Elder To: davem@davemloft.net, kuba@kernel.org Cc: bjorn.andersson@linaro.org, evgreen@chromium.org, cpratapa@codeaurora.org, elder@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next 2/4] net: ipa: fix IPA validation Date: Thu, 18 Mar 2021 23:29:21 -0500 Message-Id: <20210319042923.1584593-3-elder@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210319042923.1584593-1-elder@linaro.org> References: <20210319042923.1584593-1-elder@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org There are blocks of IPA code that sanity-check various values, at compile time where possible. Most of these checks can be done once during development but skipped for normal operation. These checks permit the driver to make certain assumptions, thereby avoiding the need for runtime error checking. The checks are defined conditionally, but not consistently. In some cases IPA_VALIDATION enables the optional checks, while in others IPA_VALIDATE is used. Fix this by using IPA_VALIDATION consistently. Signed-off-by: Alex Elder --- drivers/net/ipa/Makefile | 2 +- drivers/net/ipa/gsi_trans.c | 8 ++++---- drivers/net/ipa/ipa_cmd.c | 4 ++-- drivers/net/ipa/ipa_cmd.h | 6 +++--- drivers/net/ipa/ipa_endpoint.c | 6 +++--- drivers/net/ipa/ipa_main.c | 6 +++--- drivers/net/ipa/ipa_mem.c | 6 +++--- drivers/net/ipa/ipa_table.c | 6 +++--- drivers/net/ipa/ipa_table.h | 6 +++--- 9 files changed, 25 insertions(+), 25 deletions(-) -- 2.27.0 diff --git a/drivers/net/ipa/Makefile b/drivers/net/ipa/Makefile index afe5df1e6eeee..014ae36ac6004 100644 --- a/drivers/net/ipa/Makefile +++ b/drivers/net/ipa/Makefile @@ -1,5 +1,5 @@ # Un-comment the next line if you want to validate configuration data -#ccflags-y += -DIPA_VALIDATE +# ccflags-y += -DIPA_VALIDATION obj-$(CONFIG_QCOM_IPA) += ipa.o diff --git a/drivers/net/ipa/gsi_trans.c b/drivers/net/ipa/gsi_trans.c index 6c3ed5b17b80c..284063b39b33c 100644 --- a/drivers/net/ipa/gsi_trans.c +++ b/drivers/net/ipa/gsi_trans.c @@ -90,14 +90,14 @@ int gsi_trans_pool_init(struct gsi_trans_pool *pool, size_t size, u32 count, { void *virt; -#ifdef IPA_VALIDATE +#ifdef IPA_VALIDATION if (!size || size % 8) return -EINVAL; if (count < max_alloc) return -EINVAL; if (!max_alloc) return -EINVAL; -#endif /* IPA_VALIDATE */ +#endif /* IPA_VALIDATION */ /* By allocating a few extra entries in our pool (one less * than the maximum number that will be requested in a @@ -140,14 +140,14 @@ int gsi_trans_pool_init_dma(struct device *dev, struct gsi_trans_pool *pool, dma_addr_t addr; void *virt; -#ifdef IPA_VALIDATE +#ifdef IPA_VALIDATION if (!size || size % 8) return -EINVAL; if (count < max_alloc) return -EINVAL; if (!max_alloc) return -EINVAL; -#endif /* IPA_VALIDATE */ +#endif /* IPA_VALIDATION */ /* Don't let allocations cross a power-of-two boundary */ size = __roundup_pow_of_two(size); diff --git a/drivers/net/ipa/ipa_cmd.c b/drivers/net/ipa/ipa_cmd.c index b40f031a905a7..87e1ca2e27106 100644 --- a/drivers/net/ipa/ipa_cmd.c +++ b/drivers/net/ipa/ipa_cmd.c @@ -162,7 +162,7 @@ static void ipa_cmd_validate_build(void) #undef TABLE_SIZE } -#ifdef IPA_VALIDATE +#ifdef IPA_VALIDATION /* Validate a memory region holding a table */ bool ipa_cmd_table_valid(struct ipa *ipa, const struct ipa_mem *mem, @@ -316,7 +316,7 @@ bool ipa_cmd_data_valid(struct ipa *ipa) return true; } -#endif /* IPA_VALIDATE */ +#endif /* IPA_VALIDATION */ int ipa_cmd_pool_init(struct gsi_channel *channel, u32 tre_max) { diff --git a/drivers/net/ipa/ipa_cmd.h b/drivers/net/ipa/ipa_cmd.h index 6dd3d35cf315d..429245f075122 100644 --- a/drivers/net/ipa/ipa_cmd.h +++ b/drivers/net/ipa/ipa_cmd.h @@ -50,7 +50,7 @@ struct ipa_cmd_info { enum dma_data_direction direction; }; -#ifdef IPA_VALIDATE +#ifdef IPA_VALIDATION /** * ipa_cmd_table_valid() - Validate a memory region holding a table @@ -73,7 +73,7 @@ bool ipa_cmd_table_valid(struct ipa *ipa, const struct ipa_mem *mem, */ bool ipa_cmd_data_valid(struct ipa *ipa); -#else /* !IPA_VALIDATE */ +#else /* !IPA_VALIDATION */ static inline bool ipa_cmd_table_valid(struct ipa *ipa, const struct ipa_mem *mem, bool route, @@ -87,7 +87,7 @@ static inline bool ipa_cmd_data_valid(struct ipa *ipa) return true; } -#endif /* !IPA_VALIDATE */ +#endif /* !IPA_VALIDATION */ /** * ipa_cmd_pool_init() - initialize command channel pools diff --git a/drivers/net/ipa/ipa_endpoint.c b/drivers/net/ipa/ipa_endpoint.c index 7209ee3c31244..1a4de4e9eafcd 100644 --- a/drivers/net/ipa/ipa_endpoint.c +++ b/drivers/net/ipa/ipa_endpoint.c @@ -75,7 +75,7 @@ struct ipa_status { #define IPA_STATUS_FLAGS1_RT_RULE_ID_FMASK GENMASK(31, 22) #define IPA_STATUS_FLAGS2_TAG_FMASK GENMASK_ULL(63, 16) -#ifdef IPA_VALIDATE +#ifdef IPA_VALIDATION static bool ipa_endpoint_data_valid_one(struct ipa *ipa, u32 count, const struct ipa_gsi_endpoint_data *all_data, @@ -225,7 +225,7 @@ static bool ipa_endpoint_data_valid(struct ipa *ipa, u32 count, return true; } -#else /* !IPA_VALIDATE */ +#else /* !IPA_VALIDATION */ static bool ipa_endpoint_data_valid(struct ipa *ipa, u32 count, const struct ipa_gsi_endpoint_data *data) @@ -233,7 +233,7 @@ static bool ipa_endpoint_data_valid(struct ipa *ipa, u32 count, return true; } -#endif /* !IPA_VALIDATE */ +#endif /* !IPA_VALIDATION */ /* Allocate a transaction to use on a non-command endpoint */ static struct gsi_trans *ipa_endpoint_trans_alloc(struct ipa_endpoint *endpoint, diff --git a/drivers/net/ipa/ipa_main.c b/drivers/net/ipa/ipa_main.c index d354e3e65ec50..d95909a4aef4c 100644 --- a/drivers/net/ipa/ipa_main.c +++ b/drivers/net/ipa/ipa_main.c @@ -734,7 +734,7 @@ MODULE_DEVICE_TABLE(of, ipa_match); * */ static void ipa_validate_build(void) { -#ifdef IPA_VALIDATE +#ifdef IPA_VALIDATION /* At one time we assumed a 64-bit build, allowing some do_div() * calls to be replaced by simple division or modulo operations. * We currently only perform divide and modulo operations on u32, @@ -768,7 +768,7 @@ static void ipa_validate_build(void) BUILD_BUG_ON(!ipa_aggr_granularity_val(IPA_AGGR_GRANULARITY)); BUILD_BUG_ON(ipa_aggr_granularity_val(IPA_AGGR_GRANULARITY) > field_max(AGGR_GRANULARITY_FMASK)); -#endif /* IPA_VALIDATE */ +#endif /* IPA_VALIDATION */ } /** @@ -808,7 +808,7 @@ static int ipa_probe(struct platform_device *pdev) /* Get configuration data early; needed for clock initialization */ data = of_device_get_match_data(dev); if (!data) { - /* This is really IPA_VALIDATE (should never happen) */ + /* This is really IPA_VALIDATION (should never happen) */ dev_err(dev, "matched hardware not supported\n"); return -ENODEV; } diff --git a/drivers/net/ipa/ipa_mem.c b/drivers/net/ipa/ipa_mem.c index f25029b9ec857..6a239d49bb559 100644 --- a/drivers/net/ipa/ipa_mem.c +++ b/drivers/net/ipa/ipa_mem.c @@ -100,7 +100,7 @@ void ipa_mem_teardown(struct ipa *ipa) /* Nothing to do */ } -#ifdef IPA_VALIDATE +#ifdef IPA_VALIDATION static bool ipa_mem_valid(struct ipa *ipa, enum ipa_mem_id mem_id) { @@ -127,14 +127,14 @@ static bool ipa_mem_valid(struct ipa *ipa, enum ipa_mem_id mem_id) return false; } -#else /* !IPA_VALIDATE */ +#else /* !IPA_VALIDATION */ static bool ipa_mem_valid(struct ipa *ipa, enum ipa_mem_id mem_id) { return true; } -#endif /*! IPA_VALIDATE */ +#endif /*! IPA_VALIDATION */ /** * ipa_mem_config() - Configure IPA shared memory diff --git a/drivers/net/ipa/ipa_table.c b/drivers/net/ipa/ipa_table.c index 988f2c2886b95..aa8b3ce7e21d9 100644 --- a/drivers/net/ipa/ipa_table.c +++ b/drivers/net/ipa/ipa_table.c @@ -113,7 +113,7 @@ */ #define IPA_ZERO_RULE_SIZE (2 * sizeof(__le32)) -#ifdef IPA_VALIDATE +#ifdef IPA_VALIDATION /* Check things that can be validated at build time. */ static void ipa_table_validate_build(void) @@ -225,13 +225,13 @@ bool ipa_filter_map_valid(struct ipa *ipa, u32 filter_map) return true; } -#else /* !IPA_VALIDATE */ +#else /* !IPA_VALIDATION */ static void ipa_table_validate_build(void) { } -#endif /* !IPA_VALIDATE */ +#endif /* !IPA_VALIDATION */ /* Zero entry count means no table, so just return a 0 address */ static dma_addr_t ipa_table_addr(struct ipa *ipa, bool filter_mask, u16 count) diff --git a/drivers/net/ipa/ipa_table.h b/drivers/net/ipa/ipa_table.h index 889c2e93b1223..6017d60fb870e 100644 --- a/drivers/net/ipa/ipa_table.h +++ b/drivers/net/ipa/ipa_table.h @@ -19,7 +19,7 @@ struct ipa; /* The maximum number of route table entries (IPv4, IPv6; hashed or not) */ #define IPA_ROUTE_COUNT_MAX 15 -#ifdef IPA_VALIDATE +#ifdef IPA_VALIDATION /** * ipa_table_valid() - Validate route and filter table memory regions @@ -37,7 +37,7 @@ bool ipa_table_valid(struct ipa *ipa); */ bool ipa_filter_map_valid(struct ipa *ipa, u32 filter_mask); -#else /* !IPA_VALIDATE */ +#else /* !IPA_VALIDATION */ static inline bool ipa_table_valid(struct ipa *ipa) { @@ -49,7 +49,7 @@ static inline bool ipa_filter_map_valid(struct ipa *ipa, u32 filter_mask) return true; } -#endif /* !IPA_VALIDATE */ +#endif /* !IPA_VALIDATION */ /** * ipa_table_hash_support() - Return true if hashed tables are supported From patchwork Fri Mar 19 04:29:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 404735 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp1053379jai; Thu, 18 Mar 2021 21:30:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx0vjdru5QvvOV4tfvOxyXDtfOMbxdgHHYB0u+c2ckQ8gP4TdGwM588w9R1+05zgeaIJd5c X-Received: by 2002:a05:6402:17e9:: with SMTP id t9mr7421698edy.211.1616128217317; Thu, 18 Mar 2021 21:30:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616128217; cv=none; d=google.com; s=arc-20160816; b=w1Uqvs2jRj5eJH/7aJSlRdQ1WC3LmGxbLQo5aemuIs+BKxuhEwHkBkiOCEKcYfL43I XKv19JoxwmIIcmx6JjkUkbS2b4pk3Kc7zt8zVJKrmGYteMCfvgDVUPUjjdYY0OH0BuEG FJs/1bTXBZZz4M4E2ku1rghacNcO2Ozx5h1LhzvpK+gDvUQQ3uuxwITEsI7RgTQwDPZY Yqk8WlmaRAgli1duBZ2krR8aZmlbQCT955U+jGkdeF6+24giJpjNiWTvQWT0LQLp/pnE fbaN3u77Kv5EeQ+MZcNBVm7yc4na0ayjuHBV4mQPiaAUxjYLz787O7uBZp2Hv6ozyodV lKug== 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=hOSuT4H6WBsdge+ZQLbZaZiGAa1JAYNZuZZGRCXBZw4=; b=1Fhuf65mUlqF/hs/9DFl4ik1hbOkvGozUISiyaUE/Quw0YdaM6GmEosDCb9FE/c5r8 11FQu6LzwG7lyP26XPHxzLXnJm3Sg3sWSKScaioTOwbYv2BMazUKFkud4eL8Cpz1szt1 FevDFcxYU5k2EKETLoNwi4/7TexMk4d6QQDAvUHSBFuKE2zFJp0OvUvgh7e5bISSY4Vk CtM7xzz1MB/pECJQq9ruHelS+s8OPj+wyZBPD6YBzwgCeptEK4SWU3dWVpcK1+0TsmIL ++3zunmvXvF6q0dFi3Yj+riBdAtEedv81d9YQ9ClSdcxDU7CgIlDqY42qezbKQK7Xvmi VI5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qatE2pCu; spf=pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h20si3135507edq.97.2021.03.18.21.30.17; Thu, 18 Mar 2021 21:30:17 -0700 (PDT) Received-SPF: pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qatE2pCu; spf=pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233783AbhCSE3r (ORCPT + 8 others); Fri, 19 Mar 2021 00:29:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233742AbhCSE3a (ORCPT ); Fri, 19 Mar 2021 00:29:30 -0400 Received: from mail-io1-xd29.google.com (mail-io1-xd29.google.com [IPv6:2607:f8b0:4864:20::d29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42BDCC06175F for ; Thu, 18 Mar 2021 21:29:30 -0700 (PDT) Received: by mail-io1-xd29.google.com with SMTP id f19so4735455ion.3 for ; Thu, 18 Mar 2021 21:29:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hOSuT4H6WBsdge+ZQLbZaZiGAa1JAYNZuZZGRCXBZw4=; b=qatE2pCuVbZ9AiG8D68hOg5EioDi8h52YCrCz3/3WAkV8a4ENNF+Oh0Ye2AO3w+z4N QVI4jLPWCvqI9y1yQm5V5lAj48NbBuif9NMsOO2oWWomtTQDlFAZJhstaP4ieaTx/Flw Vsf+HSuDzsWP0IH3xMa5uEV0daiGZMvIlrQyXgRWM3Fzrz4XIl0B51jE9WeY7KjD+aDn 5P2hJX8Cyd/X59gSGPVvor3tcZ8oJjIUXat5vC5Hx/ijwtAXMXm8pDr+TEgNIn0abzQr otGreeTCR+i/6Qz6BzQBPrv6JdHz8mlEOp8eABPrk+PG4pDtVUqeM5dYy3bmeab/U5ob 2iIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hOSuT4H6WBsdge+ZQLbZaZiGAa1JAYNZuZZGRCXBZw4=; b=mGGipUU2vlkPM4PUfJSogDH55QdT6BrHEijYIJ0P8aEkv7QpGj5koKcPV3azycdkhU Og3/48/ZwtC8/Wa6jiWTNQ39sHVE4KCsDZ9k7YO1Tgoe4p+bZ1a4WMEkTNOEnAVEr8Db rldCBIWs1cO6G6zmYCMrb89LW650D+2WI//s+DpO9+/1jAmnrF1+QubV6tGn2MibnY4u EorLmXmMJ4RmyFxZP7k4bBeIkBjMX/Xe6tExoI6X3lAPGIwNRopgl7FF+xn0E2yVMDC1 1VneL3XN7cwk1iCi1XbCgHS0WwEuc/dl7/+c3kvYSjGRmD6DKFU0zCK/GxcM1RsTcbxn aZ7g== X-Gm-Message-State: AOAM530vcHi8tMNYM/8qU8N+BiYuWEOSq7yoRSJwWXe7YkJu6eg2OXBJ WJRPTUDNCEJ0AOhbKEWXgKGQog== X-Received: by 2002:a05:6602:228f:: with SMTP id d15mr1310725iod.141.1616128169777; Thu, 18 Mar 2021 21:29:29 -0700 (PDT) Received: from localhost.localdomain (c-73-185-129-58.hsd1.mn.comcast.net. [73.185.129.58]) by smtp.gmail.com with ESMTPSA id k3sm1985940ioj.35.2021.03.18.21.29.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Mar 2021 21:29:29 -0700 (PDT) From: Alex Elder To: davem@davemloft.net, kuba@kernel.org Cc: bjorn.andersson@linaro.org, evgreen@chromium.org, cpratapa@codeaurora.org, elder@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next 3/4] net: ipa: introduce ipa_assert() Date: Thu, 18 Mar 2021 23:29:22 -0500 Message-Id: <20210319042923.1584593-4-elder@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210319042923.1584593-1-elder@linaro.org> References: <20210319042923.1584593-1-elder@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Create a new macro ipa_assert() to verify that a condition is true. This produces a build-time error if the condition can be evaluated at build time; otherwise __ipa_assert_runtime() is called (described below). Another macro, ipa_assert_always() verifies that an expression yields true at runtime, and if it does not, reports an error message. When IPA validation is enabled, __ipa_assert_runtime() becomes a call to ipa_assert_always(), resulting in runtime verification of the asserted condition. Otherwise __ipa_assert_runtime() has no effect, so such ipa_assert() calls are effectively ignored. IPA assertion errors will be reported using the IPA device if possible. Signed-off-by: Alex Elder --- drivers/net/ipa/ipa_assert.h | 50 ++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 drivers/net/ipa/ipa_assert.h -- 2.27.0 diff --git a/drivers/net/ipa/ipa_assert.h b/drivers/net/ipa/ipa_assert.h new file mode 100644 index 0000000000000..7e5b9d487f69d --- /dev/null +++ b/drivers/net/ipa/ipa_assert.h @@ -0,0 +1,50 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2021 Linaro Ltd. + */ +#ifndef _IPA_ASSERT_H_ +#define _IPA_ASSERT_H_ + +#include +#include +#include + +/* Verify the expression yields true, and fail at build time if possible */ +#define ipa_assert(dev, expr) \ + do { \ + if (__builtin_constant_p(expr)) \ + compiletime_assert(expr, __ipa_failure_msg(expr)); \ + else \ + __ipa_assert_runtime(dev, expr); \ + } while (0) + +/* Report an error if the given expression evaluates to false at runtime */ +#define ipa_assert_always(dev, expr) \ + do { \ + if (unlikely(!(expr))) { \ + struct device *__dev = (dev); \ + \ + if (__dev) \ + dev_err(__dev, __ipa_failure_msg(expr)); \ + else \ + pr_err(__ipa_failure_msg(expr)); \ + } \ + } while (0) + +/* Constant message used when an assertion fails */ +#define __ipa_failure_msg(expr) "IPA assertion failed: " #expr "\n" + +#ifdef IPA_VALIDATION + +/* Only do runtime checks for "normal" assertions if validating the code */ +#define __ipa_assert_runtime(dev, expr) ipa_assert_always(dev, expr) + +#else /* !IPA_VALIDATION */ + +/* "Normal" assertions aren't checked when validation is disabled */ +#define __ipa_assert_runtime(dev, expr) \ + do { (void)(dev); (void)(expr); } while (0) + +#endif /* !IPA_VALIDATION */ + +#endif /* _IPA_ASSERT_H_ */ From patchwork Fri Mar 19 04:29:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 404736 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp1053387jai; Thu, 18 Mar 2021 21:30:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxVBx2oZ9QTmVJtcoKLLvE5cbWMA01f7xxragwenYEa2C/D7MF90XnzOegKcDNuNk4QKTPy X-Received: by 2002:a17:906:7194:: with SMTP id h20mr2182101ejk.154.1616128217993; Thu, 18 Mar 2021 21:30:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616128217; cv=none; d=google.com; s=arc-20160816; b=Omjoo5vmVB3jSbJP+LZHpCVgvqBEUYKLs1JfC0WHEL7JvaXAdL/heYgoLc4ISbpmGv lIPGrG2ieCP6VId5JtyK8BAz8h/2t91gNcA/ss49nX0sdOcSsp0FMbdN2XQXAeFwcJC+ UPdE5UfUor5l/Cj+e0Gz8NZTxuXsJyIfjAXM9G5gss//bDaP335jzUyklQjhHnSbJLnG rTZ4FF8dcLjw78EgYIYvykey+g118nLky0LmSvsb3cF9wtRkS6eOYY6mcrccVCw1SeWI OmZgW1XyKl5lJF4vNBkNorZIFJHu1m0S9VPSkZC2vquDx2GKJog+MyRvS0ErgjhVmjWd cxkw== 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=hDG6PIHC7KpW9wWS8Pp6sLnLw2dJbPgbTk+XMu+T/nA=; b=fNLO+0dUjIMtaLcL4ygmBoi44H4JAywj22fewDRb4TYoSsMkcE4bDkPGkp82ZHkjix K2J8uOvnrgbHoVD72iGZ2cpr32VLH0T/EFm7ug+UZHXjA7+f4fNiRzrQyF5EmXVsD/cb w5lu8sR9gCx1rTL4CUmPNxZQDAt2JAVW5KfWoTTR4nuXunZK+hpmn5IbwHy4l2y4I/aU puiGVBRf6ORmTg1NQaxZXo90TFTHC7ElcOr+z0eZu1p2Cqd1yOgnMwlWLtlZR7iIc3dG MDRkhHjjWLaS7IQOrtPWtx8rtpDy4sU3QuDIBXS4vn1k/pNLGojDTOnEn92eqTs8WZnX W6CA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tvHoeIoo; spf=pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h20si3135507edq.97.2021.03.18.21.30.17; Thu, 18 Mar 2021 21:30:17 -0700 (PDT) Received-SPF: pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tvHoeIoo; spf=pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233796AbhCSE3s (ORCPT + 8 others); Fri, 19 Mar 2021 00:29:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39052 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233743AbhCSE3b (ORCPT ); Fri, 19 Mar 2021 00:29:31 -0400 Received: from mail-il1-x129.google.com (mail-il1-x129.google.com [IPv6:2607:f8b0:4864:20::129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 062F0C06175F for ; Thu, 18 Mar 2021 21:29:31 -0700 (PDT) Received: by mail-il1-x129.google.com with SMTP id v3so6919587ilj.12 for ; Thu, 18 Mar 2021 21:29:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hDG6PIHC7KpW9wWS8Pp6sLnLw2dJbPgbTk+XMu+T/nA=; b=tvHoeIoo0qoEWzSw5VP/s1UhNOT6XZmP4zTSXD+hO/jDQsVFq7RlNpWz4hsliEISGm kxCsJWb9S/c+XV66AcUc5j1Vmybd262FP3BM5i7UsaWVBVC5PwNaCPKfIhUBg+VQaYvD x5qajfhRkRCsJvj6f5UJhi1MKKd8+CPRj5xgSP3okluniuNUGQhjxlKU0bNRzgQuzaW8 3glYLkFkxhlQChFi+Jv3n3YXDko+y4RD0vtaA7vpCW+W015asCiwdj+aTtQWhSOMZlkK HFk5dnJ4ZaUvVDej6NdXd+DUvuc6hESVH9pgkJCEyYKcoHTUd9TZTxnJzpEae9r/u1b+ g40g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hDG6PIHC7KpW9wWS8Pp6sLnLw2dJbPgbTk+XMu+T/nA=; b=DYIDZi+CGPJ4Vb3aB7gePn7Hi2M/9ghUnXvCGqaO6oKnU7UyFQYGIr+CDYyER/aYJg JBvv5aKvuMnaDG8jOP2yiBFqsdcgGNsEtgZKMctAyYccN3NgFIO8dstKzB8n8rViMwHM /1NvNnBE7osED/bKXgNDLidaNaiYiJGmA5aIlEfKg9D+QUoc7umDoGWrwqj/cYhkE0SN 1fMXVYQKrcZOmsJaUU1Zm+GHCUZf2LZjKikEWN803n5SHwHVvXI6RSrRrppjIIeJJu9I wMSrIj8t7hNVMDTaM04H4REPISzSEQ9EdKkp0twcA4QweYZLT7DFL9c4i6zjhRHcluHC y2Ng== X-Gm-Message-State: AOAM531KnGutFK8xREbFJmlUtVR+3XU819Oa3Uy5+ksyC/bDrzcnD8vY SYt+WjyvKJ/87GIc0Fe+kID7qw== X-Received: by 2002:a92:444e:: with SMTP id a14mr1371727ilm.215.1616128170515; Thu, 18 Mar 2021 21:29:30 -0700 (PDT) Received: from localhost.localdomain (c-73-185-129-58.hsd1.mn.comcast.net. [73.185.129.58]) by smtp.gmail.com with ESMTPSA id k3sm1985940ioj.35.2021.03.18.21.29.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Mar 2021 21:29:30 -0700 (PDT) From: Alex Elder To: davem@davemloft.net, kuba@kernel.org Cc: bjorn.andersson@linaro.org, evgreen@chromium.org, cpratapa@codeaurora.org, elder@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next 4/4] net: ipa: activate some commented assertions Date: Thu, 18 Mar 2021 23:29:23 -0500 Message-Id: <20210319042923.1584593-5-elder@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210319042923.1584593-1-elder@linaro.org> References: <20210319042923.1584593-1-elder@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Convert some commented assertion statements into real calls to ipa_assert(). If the IPA device pointer is available, provide it, otherwise pass NULL for that. There are lots more places to convert, but this serves as an initial verification of the new mechanism. The assertions here implement both runtime and build-time assertions, both with and without the device pointer. Signed-off-by: Alex Elder --- drivers/net/ipa/ipa_reg.h | 7 ++++--- drivers/net/ipa/ipa_table.c | 5 ++++- 2 files changed, 8 insertions(+), 4 deletions(-) -- 2.27.0 diff --git a/drivers/net/ipa/ipa_reg.h b/drivers/net/ipa/ipa_reg.h index 732e691e9aa62..d0de85de9f08d 100644 --- a/drivers/net/ipa/ipa_reg.h +++ b/drivers/net/ipa/ipa_reg.h @@ -9,6 +9,7 @@ #include #include "ipa_version.h" +#include "ipa_assert.h" struct ipa; @@ -212,7 +213,7 @@ static inline u32 ipa_reg_bcr_val(enum ipa_version version) BCR_HOLB_DROP_L2_IRQ_FMASK | BCR_DUAL_TX_FMASK; - /* assert(version != IPA_VERSION_4_5); */ + ipa_assert(NULL, version != IPA_VERSION_4_5); return 0x00000000; } @@ -413,7 +414,7 @@ static inline u32 ipa_header_size_encoded(enum ipa_version version, val = u32_encode_bits(size, HDR_LEN_FMASK); if (version < IPA_VERSION_4_5) { - /* ipa_assert(header_size == size); */ + ipa_assert(NULL, header_size == size); return val; } @@ -433,7 +434,7 @@ static inline u32 ipa_metadata_offset_encoded(enum ipa_version version, val = u32_encode_bits(off, HDR_OFST_METADATA_FMASK); if (version < IPA_VERSION_4_5) { - /* ipa_assert(offset == off); */ + ipa_assert(NULL, offset == off); return val; } diff --git a/drivers/net/ipa/ipa_table.c b/drivers/net/ipa/ipa_table.c index aa8b3ce7e21d9..7784b42fbaccc 100644 --- a/drivers/net/ipa/ipa_table.c +++ b/drivers/net/ipa/ipa_table.c @@ -23,6 +23,7 @@ #include "ipa_cmd.h" #include "gsi.h" #include "gsi_trans.h" +#include "ipa_assert.h" /** * DOC: IPA Filter and Route Tables @@ -237,11 +238,13 @@ static void ipa_table_validate_build(void) static dma_addr_t ipa_table_addr(struct ipa *ipa, bool filter_mask, u16 count) { u32 skip; + u32 max; if (!count) return 0; -/* assert(count <= max_t(u32, IPA_FILTER_COUNT_MAX, IPA_ROUTE_COUNT_MAX)); */ + max = max_t(u32, IPA_FILTER_COUNT_MAX, IPA_ROUTE_COUNT_MAX); + ipa_assert(&ipa->pdev->dev, max); /* Skip over the zero rule and possibly the filter mask */ skip = filter_mask ? 1 : 2;