qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: "Peter Maydell" <peter.maydell@linaro.org>,
	"Mao Zhongyi" <maozhongyi@cmss.chinamobile.com>,
	"Hervé Poussineau" <hpoussin@reactos.org>
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
	"QEMU Developers" <qemu-devel@nongnu.org>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Zhang Shengju" <zhangshengju@cmss.chinamobile.com>
Subject: Re: [Qemu-devel] [PATCH 14/22] nvram/ds1225y: Convert sysbus init function to realize function
Date: Wed, 21 Nov 2018 00:14:03 +0100	[thread overview]
Message-ID: <a7990e40-8e9d-903f-d538-0aa4124fd335@redhat.com> (raw)
In-Reply-To: <CAFEAcA9puTQZfZEK3R+LKUa_zwoEe+KyH1GEok9wiS9fZq0+5g@mail.gmail.com>

Hi Peter,

On 20/11/18 15:51, Peter Maydell wrote:
> On 19 November 2018 at 12:08, Mao Zhongyi
> <maozhongyi@cmss.chinamobile.com> wrote:
>> Use DeviceClass rather than SysBusDeviceClass in
>> nvram_sysbus_class_init().
>>
>> Cc: pbonzini@redhat.com
>> Cc: marcandre.lureau@redhat.com
>>
>> Signed-off-by: Mao Zhongyi <maozhongyi@cmss.chinamobile.com>
>> Signed-off-by: Zhang Shengju <zhangshengju@cmss.chinamobile.com>
>> ---
>>   hw/nvram/ds1225y.c | 12 +++++-------
>>   1 file changed, 5 insertions(+), 7 deletions(-)
>>
>> diff --git a/hw/nvram/ds1225y.c b/hw/nvram/ds1225y.c
>> index ad7345f288..b6ef463db0 100644
>> --- a/hw/nvram/ds1225y.c
>> +++ b/hw/nvram/ds1225y.c
>> @@ -25,6 +25,7 @@
>>   #include "qemu/osdep.h"
>>   #include "hw/sysbus.h"
>>   #include "trace.h"
>> +#include "qemu/error-report.h"
>>
>>   typedef struct {
>>       MemoryRegion iomem;
>> @@ -113,7 +114,7 @@ typedef struct {
>>       NvRamState nvram;
>>   } SysBusNvRamState;
>>
>> -static int nvram_sysbus_initfn(SysBusDevice *dev)
>> +static void nvram_sysbus_realize(DeviceState *dev, Error **errp)
>>   {
>>       SysBusNvRamState *sys = DS1225Y(dev);
>>       NvRamState *s = &sys->nvram;
>> @@ -123,20 +124,18 @@ static int nvram_sysbus_initfn(SysBusDevice *dev)
>>
>>       memory_region_init_io(&s->iomem, OBJECT(s), &nvram_ops, s,
>>                             "nvram", s->chip_size);
>> -    sysbus_init_mmio(dev, &s->iomem);
>> +    sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->iomem);
>>
>>       /* Read current file */
>>       file = s->filename ? fopen(s->filename, "rb") : NULL;
>>       if (file) {
>>           /* Read nvram contents */
>>           if (fread(s->contents, s->chip_size, 1, file) != 1) {
>> -            printf("nvram_sysbus_initfn: short read\n");
>> +            error_report("nvram_sysbus_realize: short read");
> 
> It seems a bit odd that we don't make this cause the
> device to fail its realize method, though I suppose
> it was not previously.

I think the case where the file length is <= chip_size is OK, since the 
contents buffer is zero-allocated.

Now for the other case when length > chip_size, you are right we 
shouldn't ignore it and throw an error.

However this is not related to this patch and should be addressed in a 
different patch, so for this patch:
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

This file is named ds1225y but is rather a generic way to byte-access a 
file (except the default chip_size which is 8kB for the DS1225Y).
Is there a more up-to-date way to do that nowaday?

> 
>>           }
>>           fclose(file);
>>       }
>>       nvram_post_load(s, 0);
>> -
>> -    return 0;
>>   }
>>
>>   static Property nvram_sysbus_properties[] = {
>> @@ -148,9 +147,8 @@ static Property nvram_sysbus_properties[] = {
>>   static void nvram_sysbus_class_init(ObjectClass *klass, void *data)
>>   {
>>       DeviceClass *dc = DEVICE_CLASS(klass);
>> -    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
>>
>> -    k->init = nvram_sysbus_initfn;
>> +    dc->realize = nvram_sysbus_realize;
>>       dc->vmsd = &vmstate_nvram;
>>       dc->props = nvram_sysbus_properties;
>>   }
>> --
>> 2.17.1
>>
> 
> thanks
> -- PMM
> 

  reply	other threads:[~2018-11-20 23:14 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-19 12:07 [Qemu-devel] [PATCH 00/22] QOM'ify SysBusDeviceClass->init Mao Zhongyi
2018-11-19 12:07 ` [Qemu-devel] [PATCH 01/22] musicpal: Convert sysbus init function to realize function Mao Zhongyi
2018-11-20 21:43   ` Philippe Mathieu-Daudé
2018-11-19 12:08 ` [Qemu-devel] [PATCH 02/22] block/noenand: " Mao Zhongyi
2018-11-19 12:08 ` [Qemu-devel] [PATCH 03/22] char/grlib_apbuart: " Mao Zhongyi
2018-11-19 12:08 ` [Qemu-devel] [PATCH 04/22] core/empty_slot: " Mao Zhongyi
2018-11-20 14:48   ` Peter Maydell
2018-11-20 21:25   ` Philippe Mathieu-Daudé
2018-11-19 12:08 ` [Qemu-devel] [PATCH 05/22] display/g364fb: " Mao Zhongyi
2018-11-20 17:14   ` Alistair Francis
2018-11-19 12:08 ` [Qemu-devel] [PATCH 06/22] dma/puv3_dma: " Mao Zhongyi
2018-11-20 14:46   ` Peter Maydell
2018-11-23  3:25     ` [Qemu-devel] [PATCH 06/22] dma/puv3_dma: Convert sysbus initfunction " maozy
2018-11-20 21:26   ` [Qemu-devel] [PATCH 06/22] dma/puv3_dma: Convert sysbus init function " Philippe Mathieu-Daudé
2018-11-19 12:08 ` [Qemu-devel] [PATCH 07/22] gpio/puv3_gpio: " Mao Zhongyi
2018-11-19 14:31   ` Peter Maydell
2018-11-20  1:23     ` [Qemu-devel] [PATCH 07/22] gpio/puv3_gpio: Convert sysbus initfunction " maozy
2018-11-19 12:08 ` [Qemu-devel] [PATCH 08/22] milkymist-softusb: Convert sysbus init function " Mao Zhongyi
2018-11-19 12:08 ` [Qemu-devel] [PATCH 09/22] input/pl050: " Mao Zhongyi
2018-11-19 12:08 ` [Qemu-devel] [PATCH 10/22] intc/puv3_intc: " Mao Zhongyi
2018-11-19 12:08 ` [Qemu-devel] [PATCH 11/22] milkymist-hpdmc: " Mao Zhongyi
2018-11-20 14:47   ` Peter Maydell
2018-11-20 21:29   ` Philippe Mathieu-Daudé
2018-11-19 12:08 ` [Qemu-devel] [PATCH 12/22] milkymist-pfpu: " Mao Zhongyi
2018-11-19 12:08 ` [Qemu-devel] [PATCH 13/22] puv3_pm.c: " Mao Zhongyi
2018-11-20 14:51   ` Peter Maydell
2018-11-20 21:29   ` Philippe Mathieu-Daudé
2018-11-19 12:08 ` [Qemu-devel] [PATCH 14/22] nvram/ds1225y: " Mao Zhongyi
2018-11-20 14:51   ` Peter Maydell
2018-11-20 23:14     ` Philippe Mathieu-Daudé [this message]
2018-11-19 12:08 ` [Qemu-devel] [PATCH 15/22] pci-bridge/dec: " Mao Zhongyi
2018-11-21  8:42   ` David Gibson
2018-11-19 12:08 ` [Qemu-devel] [PATCH 16/22] timer/etraxfs_timer: " Mao Zhongyi
2018-11-19 12:08 ` [Qemu-devel] [PATCH 17/22] timer/grlib_gptimer: " Mao Zhongyi
2018-11-19 12:08 ` [Qemu-devel] [PATCH 18/22] timer/puv3_ost: " Mao Zhongyi
2018-11-19 12:08 ` [Qemu-devel] [PATCH 19/22] usb/tusb6010: " Mao Zhongyi
2018-11-19 12:08 ` [Qemu-devel] [PATCH 20/22] xen_backend: " Mao Zhongyi
2018-11-20 14:49   ` Peter Maydell
2018-11-19 12:08 ` [Qemu-devel] [PATCH 21/22] event-facility: Change SysBusDeviceClass *sbdc to SysBusDeviceClass *sbc Mao Zhongyi
2018-11-19 12:25   ` Cornelia Huck
2018-11-19 14:10     ` [Qemu-devel] [qemu-s390x] " Thomas Huth
2018-11-20  1:10       ` [Qemu-devel] [qemu-s390x] [PATCH 21/22] event-facility: ChangeSysBusDeviceClass " maozy
2018-11-19 12:08 ` [Qemu-devel] [PATCH 22/22] core/sysbus: remove the SysBusDeviceClass::init path Mao Zhongyi
2018-11-19 23:31   ` Eduardo Habkost
2018-11-19 23:39     ` Eduardo Habkost
2018-11-23  3:10     ` [Qemu-devel] [PATCH 22/22] core/sysbus: remove the SysBusDeviceClass::initpath maozy
2018-11-23  9:02       ` Peter Maydell
2018-11-23  9:37         ` maozy
2018-11-23 18:16       ` Eduardo Habkost
2018-11-23 18:19         ` Peter Maydell
2018-11-25  1:24           ` maozy
2018-11-19 12:27 ` [Qemu-devel] [PATCH 00/22] QOM'ify SysBusDeviceClass->init Cornelia Huck

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=a7990e40-8e9d-903f-d538-0aa4124fd335@redhat.com \
    --to=philmd@redhat.com \
    --cc=hpoussin@reactos.org \
    --cc=maozhongyi@cmss.chinamobile.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=zhangshengju@cmss.chinamobile.com \
    /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).