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 phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9B06CECAAD5 for ; Fri, 9 Sep 2022 01:39:45 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 79F4F84AEF; Fri, 9 Sep 2022 03:39:42 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=ti.com header.i=@ti.com header.b="blgexOuA"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 58F6B84AEF; Fri, 9 Sep 2022 03:39:40 +0200 (CEST) Received: from lelv0142.ext.ti.com (lelv0142.ext.ti.com [198.47.23.249]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 0570A84A90 for ; Fri, 9 Sep 2022 03:39:36 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=mranostay@ti.com Received: from fllv0035.itg.ti.com ([10.64.41.0]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id 2891dZE3101659 for ; Thu, 8 Sep 2022 20:39:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1662687575; bh=ALlGvvgjAVXp/zH8DtMQVbC1pbc6xG/TJaopgzeVHjM=; h=From:To:CC:Subject:Date; b=blgexOuAASH8ZF9Lfir6/rQDIShSmLl74XY2JqQdeuRy3w16UWfyLkgHfbF94UngK 3eEahfiMvj8E7uEcEkpI5lygHJSqfFHSjV/wUOORAWm7QtF0WEiZE8tMOTLIpYk4v7 Xy0MnZVyQCeoBnH5Zozys2ekDOJdNmaIkXAiqGvI= Received: from DLEE107.ent.ti.com (dlee107.ent.ti.com [157.170.170.37]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 2891dZNN110640 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Thu, 8 Sep 2022 20:39:35 -0500 Received: from DLEE113.ent.ti.com (157.170.170.24) by DLEE107.ent.ti.com (157.170.170.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.6; Thu, 8 Sep 2022 20:39:35 -0500 Received: from fllv0039.itg.ti.com (10.64.41.19) by DLEE113.ent.ti.com (157.170.170.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.6 via Frontend Transport; Thu, 8 Sep 2022 20:39:35 -0500 Received: from ubuntu.ent.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0039.itg.ti.com (8.15.2/8.15.2) with ESMTP id 2891dVLs024322; Thu, 8 Sep 2022 20:39:32 -0500 From: Matt Ranostay To: CC: Matt Ranostay Subject: [PATCH] regmap: add WARN_ONCE when invalid mask is provided to regmap_field_init() Date: Thu, 8 Sep 2022 18:39:23 -0700 Message-ID: <20220909013923.69324-1-mranostay@ti.com> X-Mailer: git-send-email 2.37.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean In regmap_field_init() when a invalid mask is provided it still initializes without any warnings of it being incorrect. An example of this is when the LSB is greater than MSB a mask of zero is produced. WARN_ONCE() is not ideal for this but requires less changes to core regmap code. Based on: https://lore.kernel.org/all/20220708013125.313892-1-mranostay@ti.com/ Signed-off-by: Matt Ranostay --- drivers/core/regmap.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/core/regmap.c b/drivers/core/regmap.c index 5f98f85cfce..3100a58af2c 100644 --- a/drivers/core/regmap.c +++ b/drivers/core/regmap.c @@ -20,6 +20,7 @@ #include #include #include +#include /* * Internal representation of a regmap field. Instead of storing the MSB and @@ -649,6 +650,8 @@ static void regmap_field_init(struct regmap_field *rm_field, rm_field->reg = reg_field.reg; rm_field->shift = reg_field.lsb; rm_field->mask = GENMASK(reg_field.msb, reg_field.lsb); + + WARN_ONCE(rm_field->mask == 0, "invalid empty mask defined\n"); } struct regmap_field *devm_regmap_field_alloc(struct udevice *dev, -- 2.37.2