From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: qemu-devel@nongnu.org
Cc: "John Snow" <jsnow@redhat.com>,
qemu-trivial@nongnu.org, qemu-block@nongnu.org,
"Philippe Mathieu-Daudé" <philmd@linaro.org>
Subject: [PATCH] hw/ide: Remove unuseful IDE_DMA__COUNT definition
Date: Fri, 24 Feb 2023 16:34:10 +0100 [thread overview]
Message-ID: <20230224153410.19727-1-philmd@linaro.org> (raw)
First, IDE_DMA__COUNT represents the number of enumerated
values, but is incorrectly listed as part of the enum.
Second, IDE_DMA_CMD_str() is internal to core.c and only
takes sane enums from ide_dma_cmd. So no need to check the
'enval' argument is within the enum range. Only checks
IDE_DMA_CMD_lookup[] entry is not NULL.
Both combined, IDE_DMA__COUNT can go.
Reduce IDE_DMA_CMD_lookup[] scope which is only used locally.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
hw/ide/core.c | 10 +++++-----
include/hw/ide/internal.h | 3 ---
2 files changed, 5 insertions(+), 8 deletions(-)
diff --git a/hw/ide/core.c b/hw/ide/core.c
index 5d1039378f..8bf61e7267 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -63,19 +63,19 @@ static const int smart_attributes[][12] = {
{ 190, 0x03, 0x00, 0x45, 0x45, 0x1f, 0x00, 0x1f, 0x1f, 0x00, 0x00, 0x32},
};
-const char *IDE_DMA_CMD_lookup[IDE_DMA__COUNT] = {
+static const char *IDE_DMA_CMD_lookup[] = {
[IDE_DMA_READ] = "DMA READ",
[IDE_DMA_WRITE] = "DMA WRITE",
[IDE_DMA_TRIM] = "DMA TRIM",
- [IDE_DMA_ATAPI] = "DMA ATAPI"
+ [IDE_DMA_ATAPI] = "DMA ATAPI",
};
static const char *IDE_DMA_CMD_str(enum ide_dma_cmd enval)
{
- if ((unsigned)enval < IDE_DMA__COUNT) {
- return IDE_DMA_CMD_lookup[enval];
+ if (!IDE_DMA_CMD_lookup[enval]) {
+ return "DMA UNKNOWN CMD";
}
- return "DMA UNKNOWN CMD";
+ return IDE_DMA_CMD_lookup[enval];
}
static void ide_dummy_transfer_stop(IDEState *s);
diff --git a/include/hw/ide/internal.h b/include/hw/ide/internal.h
index fc0aa81a88..e864fe8caf 100644
--- a/include/hw/ide/internal.h
+++ b/include/hw/ide/internal.h
@@ -352,11 +352,8 @@ enum ide_dma_cmd {
IDE_DMA_WRITE,
IDE_DMA_TRIM,
IDE_DMA_ATAPI,
- IDE_DMA__COUNT
};
-extern const char *IDE_DMA_CMD_lookup[IDE_DMA__COUNT];
-
#define ide_cmd_is_read(s) \
((s)->dma_cmd == IDE_DMA_READ)
--
2.38.1
next reply other threads:[~2023-02-24 15:34 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-24 15:34 Philippe Mathieu-Daudé [this message]
2023-03-14 17:04 ` [PATCH] hw/ide: Remove unuseful IDE_DMA__COUNT definition Philippe Mathieu-Daudé
2023-05-17 21:39 ` John Snow
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230224153410.19727-1-philmd@linaro.org \
--to=philmd@linaro.org \
--cc=jsnow@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).