From nobody Sat Nov 23 15:21:07 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1732089279; cv=none; d=zohomail.com; s=zohoarc; b=be8IjAfduTV1f4OZfQoQ/eGFkKLMIQjRZCioC8Mb4fdUv17cSclHLT/woszfNDNcXnmDNRwFoq+AqhpvtMq5lyR0AYKZ9Nlek7IuFOYGkAjDcVtqoYVQaLch4k3l9JyVBKRVQfN04pQx8eAoaewzGBn1jcoglQY/kPoynPzyC+k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1732089279; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:Message-Id:Reply-To:To; bh=Bi4v+nZMri7qo5o9uiT+S514uJOdE4p14PmNQibE+6M=; b=jA+ptF7YOGmN3wt2SuB0DouAmqjuLmkpKhQJU3ZpuTpNdqNFovg+WJ4U3noo6dMsIGPgTGt4XICvadMDpXuF2CUqHj2dkZzjD+isjyigTCcXohVJ/RbrnbKj7CQT1tqAt1GJCopXHyHf+DSWNGTLkC9Iqdnul1AjXbWOr7k/ytE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1732089279734163.51780343036376; Tue, 19 Nov 2024 23:54:39 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tDfX3-0007Rx-8p; Wed, 20 Nov 2024 02:53:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tDfX1-0007QG-Fq for qemu-devel@nongnu.org; Wed, 20 Nov 2024 02:53:47 -0500 Received: from mail-ed1-x536.google.com ([2a00:1450:4864:20::536]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tDfWz-00009c-Kv for qemu-devel@nongnu.org; Wed, 20 Nov 2024 02:53:47 -0500 Received: by mail-ed1-x536.google.com with SMTP id 4fb4d7f45d1cf-5cef772621eso8250226a12.3 for ; Tue, 19 Nov 2024 23:53:45 -0800 (PST) Received: from finn.fritz.box ([2a02:8109:8384:1400:37e7:543e:4254:db4f]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa20df265bbsm738395666b.38.2024.11.19.23.53.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Nov 2024 23:53:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732089224; x=1732694024; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Bi4v+nZMri7qo5o9uiT+S514uJOdE4p14PmNQibE+6M=; b=LiY2JOq+NHTpG+rrnf5T0W5UxyO+AFwQQI/LZ/H/zclKQEEdV021Ie4B4jOQc+z1ml FN4UlPZOqiJNLBHSldQrgnv3IgjoQuJCIUlGoFi6BJzMVptLhZQY0aoaNC2LBr0VXzK3 Sr7kfpcYuDdgBgIxAwOwsEIScnBQp6FM46kndhn9H7O8zaTGEj9GNo3eOYP7/P8bp1VL RwdOh+P+9RJEOJTmqedPVAC2M4TVrYAgVBMUTlIirD9OeXOWfUMVF9X7r4sldR7aw5jw r+8vimi9V4kgOqQwMomcDYGO4G79AJhxZgDJJA8SImeiy9EtO+rH6W8FbLFsGhNwCurO zAvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732089224; x=1732694024; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Bi4v+nZMri7qo5o9uiT+S514uJOdE4p14PmNQibE+6M=; b=hHjkh0guqzKk578xOu+nKJXEBGBBz4we+0SRd6hrNR4zo1hGOLzBduQypa7mzGo9/d h1tZVsos3c0pJHbZZ03Apu201/fkViHxfsP88aSZES4RiOR2KttdNJ4IadlaHIytLoom bOnOAIWTXiSlXdHunSJYtnGVgJmSCwBxfnHk1UzT2lPt/ZZS0WevXkbVOMQpWJRtmgQB F/ekd4iB3bNyTB/hiaBQqZ4x7HUfwYwH9tAjhnPiD/X0DNIPW9httfoKTGMBo8mfFw4j iVCIJDA+Hf0qQU53Y9BE1Qv2XUPLUeFmUbPZy59aUYAtzSJeNFkrBbvtmBI7OxGRKRC5 BDdg== X-Forwarded-Encrypted: i=1; AJvYcCWxO1G2+9E0SrVSvC7gW+6dBCaNUFB+H3pgnhCgAOluH0R7ckNpYki6tv7TW50h7X71DK4RAhVpmvKK@nongnu.org X-Gm-Message-State: AOJu0YxwIJeu4Z2esWzdqmbBDZCd3SHYNEaG5HlIVJGuvzyU5WGC5fd4 ro6cFhKyB3dq8RXzJuDbzaBQxpP5zh0UaFcU6NKLZlrd0oSTaKb0 X-Google-Smtp-Source: AGHT+IHd0R0h6iq72TbjMbAT5LOQ82WbefuctmcYQGUnB1FqwAvDM3wWqt0vIGWKrfYZ3s94G7S01w== X-Received: by 2002:a17:907:c1f:b0:a99:499f:4cb7 with SMTP id a640c23a62f3a-aa4dd551cf4mr137855466b.23.1732089223736; Tue, 19 Nov 2024 23:53:43 -0800 (PST) From: Roman Penyaev To: Cc: Roman Penyaev , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Peter Maydell , =?UTF-8?q?Cl=C3=A9ment=20Mathieu--Drif?= , qemu-devel@nongnu.org Subject: [PATCH v2 1/2] chardev/char-mux: shift unsigned long to avoid 32-bit overflow Date: Wed, 20 Nov 2024 08:53:20 +0100 Message-Id: <20241120075321.27143-2-r.peniaev@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241120075321.27143-1-r.peniaev@gmail.com> References: <20241120075321.27143-1-r.peniaev@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::536; envelope-from=r.peniaev@gmail.com; helo=mail-ed1-x536.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1732089280620116600 Allthough the size of MAX_MUX is equal to 4 and likely will never change, this patch changes type of constant to unsigned long to be on the safe side. Also add a static compile check that MAX_MUX never bigger than `sizeof(d->mux_bitset)`. Signed-off-by: Roman Penyaev Reviewed-by: "Marc-Andr=C3=A9 Lureau" Cc: Peter Maydell : Reviewed-by: Cl=C3=A9ment Mathieu--Drif Cc: qemu-devel@nongnu.org --- chardev/char-mux.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/chardev/char-mux.c b/chardev/char-mux.c index bda5c45e6058..355520714979 100644 --- a/chardev/char-mux.c +++ b/chardev/char-mux.c @@ -316,6 +316,8 @@ bool mux_chr_attach_frontend(MuxChardev *d, CharBackend= *b, { unsigned int bit; =20 + QEMU_BUILD_BUG_ON(MAX_MUX > sizeof(d->mux_bitset)); + bit =3D find_next_zero_bit(&d->mux_bitset, MAX_MUX, 0); if (bit >=3D MAX_MUX) { error_setg(errp, @@ -325,7 +327,7 @@ bool mux_chr_attach_frontend(MuxChardev *d, CharBackend= *b, return false; } =20 - d->mux_bitset |=3D (1 << bit); + d->mux_bitset |=3D (1ul << bit); d->backends[bit] =3D b; *tag =3D bit; =20 @@ -341,7 +343,7 @@ bool mux_chr_detach_frontend(MuxChardev *d, unsigned in= t tag) return false; } =20 - d->mux_bitset &=3D ~(1 << bit); + d->mux_bitset &=3D ~(1ul << bit); d->backends[bit] =3D NULL; =20 return true; --=20 2.34.1 From nobody Sat Nov 23 15:21:07 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1732089255; cv=none; d=zohomail.com; s=zohoarc; b=IqrHztF5gjSvRfoitCRYWSzxWp/kF4rychUQomr0olX83KVceQBsMy2zo6cxuuDYU39i6sW6Kc7PKvKvrEEj3kt4AuhCNdswcj6VqLYACcEJE6rAWAVt59kTjBqFz4VCcjy+9zaBhd/5YceLSfyFBIy3/j3Ksn8p4yjc3RO2onA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1732089255; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:Message-Id:Reply-To:To; bh=G6GJ6dUiJm9oVft1YxBq0Y3GSW+27D+0bsvHZhFvYqU=; b=mPSQ2I9Vt95njuRKIsxtDX8RC1sw7khaFXJdDgG8+ehMs9FDOyEgVbExsRSrnKVQ/Xf6wIe/kWKnnV5opuoHhuQfw/X936Lbg1K8l+8bgqjXrMfK13gGkhN/ac8Cl0upPvErT6TZw9i6XoY209x8iY4NDu+vnWn61BzUcAmMw5k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1732089255702654.919781767853; Tue, 19 Nov 2024 23:54:15 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tDfX4-0007SO-FH; Wed, 20 Nov 2024 02:53:50 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tDfX2-0007R5-DZ for qemu-devel@nongnu.org; Wed, 20 Nov 2024 02:53:48 -0500 Received: from mail-ej1-x632.google.com ([2a00:1450:4864:20::632]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tDfX0-00009k-MJ for qemu-devel@nongnu.org; Wed, 20 Nov 2024 02:53:47 -0500 Received: by mail-ej1-x632.google.com with SMTP id a640c23a62f3a-a9a6acac4c3so298591566b.0 for ; Tue, 19 Nov 2024 23:53:46 -0800 (PST) Received: from finn.fritz.box ([2a02:8109:8384:1400:37e7:543e:4254:db4f]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa20df265bbsm738395666b.38.2024.11.19.23.53.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Nov 2024 23:53:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732089225; x=1732694025; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=G6GJ6dUiJm9oVft1YxBq0Y3GSW+27D+0bsvHZhFvYqU=; b=AyvRLAsUaRpzllgMejd8IDtpiMbCrfbCasR0RIDrgMJ6ETGgvNCZ6XuGRGaa8ugodJ yUJq76/o94/vXROoS1WNuA1pZ2sgJ/lJQSsLR24KvDy1EzFn2cDXXZqhSSpNwqOvet7C 1z3Dz/vS38xi1VpL/N/kx2mqXXkJLvRUsr4V3eSFHfGJcSx6MAVcOPDWeE0jmjTfbcey HcZ4cArpmOOZQ8VbvpNXiFxu1/Ubmwt9NNybOit+FLy7q71Lz6iK0AIlETA5sGy+tlP0 WiwfBHEAdJ4s11MoqQbqoEAYZj1/VJzr/mMdFEpPcicUYymTfmuoSPkI2QAV0+Aehjco s2QA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732089225; x=1732694025; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=G6GJ6dUiJm9oVft1YxBq0Y3GSW+27D+0bsvHZhFvYqU=; b=YdqMkAa3NuJ+nkqMrNP7aOW3rUfooObMdkcZxYHH3N45IMJ0r+rOXsb2NBJRAlum4Z kU/Yssg/xcJb4msvPG1q9lWOMow+bO5QLs8KeJDH+S1Ra4vNI3Jjhlw9qaPDy5ejdhGa jHPuvrZk+fOZox0DCuQZe9HyuOiAexM7NMtMUkQ95Ba1mfrH0VYcbz1kgdOYQFvxfzjI VhN5V5QdgKpxxo2My4vyKm43bTIinB0rjJ3tF+HsWAcgHX/rpB5prX+cCK9S49EbpNTt cNzxFEinJAQT+Vkm77xnQSIVSt8oBZdsHH00bvNadTMSK7P70fmnMPe9Vv/lTYinuRmY K/eA== X-Forwarded-Encrypted: i=1; AJvYcCXj7PyvVUwRbqc8oZ1xc3L1t0ICRDJiY5BC8w56V4bLNAm+Am8OkgivYFQXlsa5/C2/iThGyc/M14wA@nongnu.org X-Gm-Message-State: AOJu0YwCZRwJ/uCGIkEHa4fF/4mkxa1acanRc61tzn09uApNRBbVVUzx UHpvD5UZdZmD3fAyPVBIHWyw0BFe5RRMnhim3Ejyqt/YchsEWaMOKAt/aA== X-Google-Smtp-Source: AGHT+IEQSkdF3/W+1eGMG6c8GkF+qAolZKC1bWw9sZxJjwnRsndX7FTJ5F9TahzXvzuX3fJi0/qqCQ== X-Received: by 2002:a17:907:1b02:b0:a9a:9b1:f972 with SMTP id a640c23a62f3a-aa4dd71b723mr158971766b.40.1732089224859; Tue, 19 Nov 2024 23:53:44 -0800 (PST) From: Roman Penyaev To: Cc: Roman Penyaev , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Peter Maydell , =?UTF-8?q?Cl=C3=A9ment=20Mathieu--Drif?= , qemu-devel@nongnu.org Subject: [PATCH v2 2/2] chardev/char-mux: make boolean bit check instead of find_next_bit() Date: Wed, 20 Nov 2024 08:53:21 +0100 Message-Id: <20241120075321.27143-3-r.peniaev@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241120075321.27143-1-r.peniaev@gmail.com> References: <20241120075321.27143-1-r.peniaev@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::632; envelope-from=r.peniaev@gmail.com; helo=mail-ej1-x632.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1732089257810116600 This patch simplifies (and makes less confusing) bit checks by replacing `find_next_bit()` calls with boolean AND operation. Resolves: Coverity CID 1563776 Signed-off-by: Roman Penyaev Reviewed-by: "Marc-Andr=C3=A9 Lureau" Cc: Peter Maydell Reviewed-by: Cl=C3=A9ment Mathieu--Drif Cc: qemu-devel@nongnu.org --- chardev/char-mux.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/chardev/char-mux.c b/chardev/char-mux.c index 355520714979..f613a22e3758 100644 --- a/chardev/char-mux.c +++ b/chardev/char-mux.c @@ -336,15 +336,12 @@ bool mux_chr_attach_frontend(MuxChardev *d, CharBacke= nd *b, =20 bool mux_chr_detach_frontend(MuxChardev *d, unsigned int tag) { - unsigned int bit; - - bit =3D find_next_bit(&d->mux_bitset, MAX_MUX, tag); - if (bit !=3D tag) { + if (!(d->mux_bitset & (1ul << tag))) { return false; } =20 - d->mux_bitset &=3D ~(1ul << bit); - d->backends[bit] =3D NULL; + d->mux_bitset &=3D ~(1ul << tag); + d->backends[tag] =3D NULL; =20 return true; } @@ -353,7 +350,7 @@ void mux_set_focus(Chardev *chr, unsigned int focus) { MuxChardev *d =3D MUX_CHARDEV(chr); =20 - assert(find_next_bit(&d->mux_bitset, MAX_MUX, focus) =3D=3D focus); + assert(d->mux_bitset & (1ul << focus)); =20 if (d->focus !=3D -1) { mux_chr_send_event(d, d->focus, CHR_EVENT_MUX_OUT); --=20 2.34.1