All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
To: qemu-devel@nongnu.org
Cc: "Corey Minyard" <cminyard@mvista.com>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	"Andrew Jeffery" <andrew@aj.id.au>,
	"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
	qemu-arm@nongnu.org, "Cédric Le Goater" <clg@kaod.org>,
	"Joel Stanley" <joel@jms.id.au>
Subject: [PATCH v4 3/8] hw/misc/pca9552: Use the PCA9552_PIN_COUNT definition
Date: Sun, 21 Jun 2020 00:58:49 +0200	[thread overview]
Message-ID: <20200620225854.31160-4-f4bug@amsat.org> (raw)
In-Reply-To: <20200620225854.31160-1-f4bug@amsat.org>

The current code models the PCA9552, but there are comments
saying the code could be easily adapted for the rest of the
PCA955x family.
Since we assume we have at most 16 pins (for the PCA9552),
add a definition and check the instance doesn't use more than
this number. This makes the code a bit safer in case other
PCA955x devices are added.

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 hw/misc/pca9552.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/hw/misc/pca9552.c b/hw/misc/pca9552.c
index cfefb8fce8..b97fc2893c 100644
--- a/hw/misc/pca9552.c
+++ b/hw/misc/pca9552.c
@@ -303,6 +303,17 @@ static void pca9552_initfn(Object *obj)
     }
 }
 
+static void pca9552_realize(DeviceState *dev, Error **errp)
+{
+    PCA9552State *s = PCA9552(dev);
+
+    if (s->nr_leds > PCA9552_PIN_COUNT) {
+        error_setg(errp, "%s invalid led count %u (max: %u)",
+                   __func__, s->nr_leds, PCA9552_PIN_COUNT);
+        return;
+    }
+}
+
 static void pca9552_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
@@ -311,6 +322,7 @@ static void pca9552_class_init(ObjectClass *klass, void *data)
     k->event = pca9552_event;
     k->recv = pca9552_recv;
     k->send = pca9552_send;
+    dc->realize = pca9552_realize;
     dc->reset = pca9552_reset;
     dc->vmsd = &pca9552_vmstate;
 }
-- 
2.21.3



  parent reply	other threads:[~2020-06-20 23:00 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-20 22:58 [PATCH v4 0/8] hw/misc/pca9552: Trace GPIO change events Philippe Mathieu-Daudé
2020-06-20 22:58 ` [PATCH v4 1/8] hw/i2c/core: Add i2c_try_create_slave() and i2c_realize_and_unref() Philippe Mathieu-Daudé
2020-06-22  8:28   ` Philippe Mathieu-Daudé
2020-06-22 15:17   ` Markus Armbruster
2020-06-22 15:41     ` Philippe Mathieu-Daudé
2020-06-23  7:26       ` Markus Armbruster
2020-06-20 22:58 ` [PATCH v4 2/8] hw/misc/pca9552: Replace magic value by PCA9552_PIN_COUNT definition Philippe Mathieu-Daudé
2020-06-22  6:27   ` Cédric Le Goater
2020-06-20 22:58 ` Philippe Mathieu-Daudé [this message]
2020-06-22  6:25   ` [PATCH v4 3/8] hw/misc/pca9552: Use the " Cédric Le Goater
2020-06-22  8:37     ` Philippe Mathieu-Daudé
2020-06-22 13:15       ` Cédric Le Goater
2020-06-20 22:58 ` [PATCH v4 4/8] hw/misc/pca9552: Add a 'description' property for debugging purpose Philippe Mathieu-Daudé
2020-06-22  6:27   ` Cédric Le Goater
2020-06-22  8:31     ` Philippe Mathieu-Daudé
2020-06-22 13:24       ` Cédric Le Goater
2020-06-25  6:37         ` Markus Armbruster
2020-06-25  8:12           ` Philippe Mathieu-Daudé
2020-06-25 14:23             ` Philippe Mathieu-Daudé
2020-06-26  5:49               ` Markus Armbruster
2020-06-26  9:43                 ` Philippe Mathieu-Daudé
2020-06-27  6:52                   ` Markus Armbruster
2020-06-20 22:58 ` [PATCH v4 5/8] hw/misc/pca9552: Trace GPIO High/Low events Philippe Mathieu-Daudé
2020-06-22  6:47   ` Cédric Le Goater
2020-06-20 22:58 ` [PATCH v4 6/8] hw/arm/aspeed: Describe each PCA9552 device Philippe Mathieu-Daudé
2020-06-22  6:49   ` Cédric Le Goater
2020-06-22  8:35     ` Philippe Mathieu-Daudé
2020-06-24 16:54       ` Philippe Mathieu-Daudé
2020-06-24 17:02         ` Cédric Le Goater
2020-06-20 22:58 ` [PATCH v4 7/8] hw/misc/pca9552: Trace GPIO change events Philippe Mathieu-Daudé
2020-06-22  7:01   ` Cédric Le Goater
2020-06-22  9:52     ` Philippe Mathieu-Daudé
2020-06-20 22:58 ` [PATCH v4 8/8] hw/misc/pca9552: Model qdev output GPIOs Philippe Mathieu-Daudé
2020-06-22  7:02   ` Cédric Le Goater

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=20200620225854.31160-4-f4bug@amsat.org \
    --to=f4bug@amsat.org \
    --cc=andrew@aj.id.au \
    --cc=clg@kaod.org \
    --cc=cminyard@mvista.com \
    --cc=joel@jms.id.au \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.