From nobody Tue Feb 10 02:30:25 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of _spf.google.com designates 209.85.128.49 as permitted sender) client-ip=209.85.128.49; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wm1-f49.google.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.128.49 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1627496258; cv=none; d=zohomail.com; s=zohoarc; b=YA4rhE8zSKvdci5tkT6eu7wqOifkFAIisNKti1h2T7h/LOrg3Y2Dq5g/cJfdA9oJ+XZPQVS1FEsGfXHbMAVVA+/3Fk5WRtVltnks5wIwD7o+/uuK3z1l1ShYsOlHPvRUecxfs2it8CwfiOJRT20Xv64SRpR3z13e7PPTS6y4ErY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1627496258; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Sender:Subject:To; bh=rpJr73sHcD06uaEUnanxw7L+gRVTgFYkDb7sUWR7li8=; b=S2coGvBsq2AmUHiwPQtbVZDbIHxXVisAYiqJEDmQJp71jjfSuqUMNBrWUHgvHfFgd7tKHl6Q2Y6d5cqtAM40nt/jBg1QWvn0A7+Nr40fniGJbup3XvFFkvuGP46jIUBqI7x1Wvefw0c5BrRmndpeRuVBNY0xEaA1UloJHemxqF4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.128.49 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) by mx.zohomail.com with SMTPS id 1627496258437218.14454589026968; Wed, 28 Jul 2021 11:17:38 -0700 (PDT) Received: by mail-wm1-f49.google.com with SMTP id f14-20020a05600c154eb02902519e4abe10so5001084wmg.4 for ; Wed, 28 Jul 2021 11:17:37 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.. (122.red-83-42-66.dynamicip.rima-tde.net. [83.42.66.122]) by smtp.gmail.com with ESMTPSA id k17sm605872wrw.53.2021.07.28.11.17.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jul 2021 11:17:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rpJr73sHcD06uaEUnanxw7L+gRVTgFYkDb7sUWR7li8=; b=IZlCmLCtZtTVWI/l7DJ2ATbnmmDJMYSGAJZVba0a8irrPX6zOYMF3OYFWkslxvJzh8 2LIO6Tira7B594R6Sxr7011d+0l9qwhlviexow7ZsHzSynWeVzWjPNRgGyhU70P8/906 8ly4XwuJi+T83lwtNrnwBSM72iB1xfCcFhr27HkRUbTA1OAJ6e1N7DoHfMNfJwkwV/km itGFvxAe2LTzEXRSXbi9AOiRODoCfTONeifdcOW+ZYpL/bFy23MJ2bM0nt5nZqS+WfdJ XredUAhkyw3ldWYfhjKx0qnllJ7tKgJoTNp1SYmxOHAC411C8i/o8z06kMEBJRG5/CX1 BleA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=rpJr73sHcD06uaEUnanxw7L+gRVTgFYkDb7sUWR7li8=; b=eG5C20e5KgP732NuhY1az3JcEq7PaVFx11gyCuTbYP/s9fbv1gtb/q87A8UTMlj5Uy 4JL8tZdr5g5TXUcJRYVGs1jk8S15odzcgjZRS+H4C9WXyc+1aQuagQhlBp9JBJDCXX/L 5jAmefrklIrvzQehNOTYyDo3W1uMOYAl7pdY0MuHQp/ZqDQFIJXIb3/a//MXTXT3dPTK VTlQvBiE4f4XsdJiEIeLLt89lm5i5v34m2t6NdTiCUcSh6eZzVwEOMjB8vS4gUZfl15o dmhj0u+PPZZVy+qsvjKCzgFhbMkb6DeF2DLBgx7dyXap/jj60WHodHX6vIix8ozXhFnK IBlw== X-Gm-Message-State: AOAM531y/3/vJC3aVf7UbIdqs+D64wBvJaPaZjY9GIFdBfVMWrQkVG9y SCbTv3swsU7p8Dc6aXstWqg= X-Google-Smtp-Source: ABdhPJzkJ8R6AgWyZK+P3LG7TxygmbudutwlPUmcX9tFnKkwLuz2XHJPqCjxxXv8x1bg1JyF+PYMRQ== X-Received: by 2002:a1c:7314:: with SMTP id d20mr10670921wmb.156.1627496256645; Wed, 28 Jul 2021 11:17:36 -0700 (PDT) Sender: =?UTF-8?Q?Philippe_Mathieu=2DDaud=C3=A9?= From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Bin Meng , qemu-block@nongnu.org, qemu-arm@nongnu.org, Alexander Bulekov , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH-for-6.1 1/3] hw/sd/sdcard: Document out-of-range addresses for SEND_WRITE_PROT Date: Wed, 28 Jul 2021 20:17:26 +0200 Message-Id: <20210728181728.2012952-2-f4bug@amsat.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210728181728.2012952-1-f4bug@amsat.org> References: <20210728181728.2012952-1-f4bug@amsat.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1627496260284100001 Per the 'Physical Layer Simplified Specification Version 3.01', Table 4-22: 'Block Oriented Write Protection Commands' SEND_WRITE_PROT (CMD30) If the card provides write protection features, this command asks the card to send the status of the write protection bits [1]. [1] 32 write protection bits (representing 32 write protect groups starting at the specified address) [...] The last (least significant) bit of the protection bits corresponds to the first addressed group. If the addresses of the last groups are outside the valid range, then the corresponding write protection bits shall be set to 0. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alexander Bulekov --- hw/sd/sd.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 1f964e022b1..707dcc12a14 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -822,7 +822,14 @@ static uint32_t sd_wpbits(SDState *sd, uint64_t addr) =20 for (i =3D 0; i < 32; i++, wpnum++, addr +=3D WPGROUP_SIZE) { assert(wpnum < sd->wpgrps_size); - if (addr < sd->size && test_bit(wpnum, sd->wp_groups)) { + if (addr >=3D sd->size) { + /* + * If the addresses of the last groups are outside the valid r= ange, + * then the corresponding write protection bits shall be set t= o 0. + */ + continue; + } + if (test_bit(wpnum, sd->wp_groups)) { ret |=3D (1 << i); } } --=20 2.31.1