[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 2/2] ios: combine all global states into a single struct
From: |
Mohammad-Reza Nabipoor |
Subject: |
Re: [PATCH 2/2] ios: combine all global states into a single struct |
Date: |
Sun, 25 Sep 2022 21:43:34 +0330 |
Hi Jose.
On Sun, Sep 25, 2022 at 01:18:00PM +0200, Jose E. Marchesi wrote:
> > diff --git a/libpoke/ios-dev.h b/libpoke/ios-dev.h
> > index 3be1c295..71628504 100644
> > --- a/libpoke/ios-dev.h
> > +++ b/libpoke/ios-dev.h
> > @@ -63,7 +63,6 @@ struct ios_dev_if
> > uint64_t (*get_flags) (void *dev);
> > ios_dev_off (*size) (void *dev);
> > int (*flush) (void *dev, ios_dev_off offset);
> > - void *data;
> > };
>
> I understand the part about putting all global state in a single struct,
> but why is the `data' field in struct ios_dev_if no longer necessary,
> and how is it related to that?
>
So the idea is to put everything in a single struct, and in the next
step, we can `malloc' the struct for each instance of libpoke.
The problem with `data' is that it should be unique per libpoke instance.
And so, the array of `struct ios_dev_if's
(i.e. `static struct ios_dev_if *ios_dev_ifs[]') should be allocated by
`malloc' for each libpoke instance (and I've sent an eariler patch with
this implementation, and it got rejected).
And, after applying the "[PATCH 1/2] ios: track sub IOS devices" patch, the
only IOS device that needs `data' is "foreign IOD". So I'm handling
this special case in `struct ios_context` (please note `void
*foreign_dev_if_data`
field):
> > +struct ios_context
> > +{
> > + int next_id; /* Next available IOS id. */
> > + struct ios *io_list; /* List of all IO spaces. */
> > + struct ios *cur_io; /* Pointer to the current IOS. */
> > + void *foreign_dev_if_data; /* User-defined data for foreign device. */
> > +};
> >
I think this version of patch is better than my eariler one.
Regards,
Mohammad-Reza