public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Marcin Wojtas <mw@semihalf.com>
To: Leif Lindholm <leif.lindholm@linaro.org>
Cc: edk2-devel-01 <edk2-devel@lists.01.org>,
	Ard Biesheuvel <ard.biesheuvel@linaro.org>,
	 nadavh@marvell.com, "jsd@semihalf.com" <jsd@semihalf.com>,
	Grzegorz Jaszczyk <jaz@semihalf.com>,
	 Kostya Porotchkin <kostap@marvell.com>
Subject: Re: [platforms: PATCH v2 06/12] Marvell/Drivers: MvBoardDesc: Extend protocol with GPIO support
Date: Tue, 15 Jan 2019 11:05:12 +0100	[thread overview]
Message-ID: <CAPv3WKf73HjcEU2LzjutU8z+2dVh368n9CXpiOkkNB3xC+becQ@mail.gmail.com> (raw)
In-Reply-To: <20190115095612.v7qwnmttzptayhee@bivouac.eciton.net>

wt., 15 sty 2019 o 10:56 Leif Lindholm <leif.lindholm@linaro.org> napisał(a):
>
> On Tue, Jan 15, 2019 at 07:05:42AM +0100, Marcin Wojtas wrote:
> > > > index f71bfc4..e348b85 100644
> > > > --- a/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.c
> > > > +++ b/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.c
> > > > @@ -100,6 +100,48 @@ MvBoardDescComPhyGet (
> > > >
> > > >  STATIC
> > > >  EFI_STATUS
> > > > +MvBoardGpioDescriptionGet (
> > > > +  IN MARVELL_BOARD_DESC_PROTOCOL    *This,
> > > > +  IN OUT MV_BOARD_GPIO_DESCRIPTION **GpioDescription
> > > > +  )
> > > > +{
> > > > +  MV_BOARD_GPIO_DESCRIPTION *Description;
> > >
> > > My request on v1 was that this be refactored from a STATIC local
> > > variable to a global variable.
> > >
> > > > +  UINTN SoCGpioCount, GpioExpanderCount;
> > > > +  MV_GPIO_EXPANDER *GpioExpanders;
> > > > +  GPIO_CONTROLLER *SoCGpio;
> > > > +  EFI_STATUS Status;
> > > > +
> > > > +  /* Get SoC data about all available GPIO controllers */
> > > > +  Status = ArmadaSoCGpioGet (&SoCGpio, &SoCGpioCount);
> > > > +  if (EFI_ERROR (Status)) {
> > > > +    return Status;
> > > > +  }
> > > > +
> > > > +  /* Get per-board information about all available I2C IO expanders */
> > >
> > > GPIO
> >
> > OK.
> >
> > >
> > > > +  Status = ArmadaBoardGpioExpanderGet (&GpioExpanders, &GpioExpanderCount);
> > > > +  if (EFI_ERROR (Status)) {
> > > > +    return Status;
> > > > +  }
> > > > +
> > > > +  /* Allocate and fill board description */
> > > > +  Description = AllocateZeroPool (sizeof (MV_BOARD_GPIO_DESCRIPTION));
> > >
> > > Instead, this space is now dynamically allocated. But none of the call
> > > sites actually change, leading to potential memory leaks.
> > >
> > > I don't have a problem if you prefer an alternative solution to the
> > > one I propose, but please discuss the change first rather than
> > > submitting a new revision containing something I didn't ask for.
> >
> > Indeed, I could have asked, but didn't want to spoil your Christmas
> > time with questions, especially gitven it was 3+ weeks from review:/
>
> It's not like I was checking email :)
>
> > Anyway, I tried to play with the MV_BOARD_GPIO_DESCRIPTION to be the
> > global variable, but was not convinced by the outcome. My biggest
> > objection to the global variable and checking whether it's NULL in the
> > consumer driver is following - until now all users of the
> > BoardDescProtocol 'know' and call only the relevant protocol routine,
> > everything what happens underneath (PCDs, variable names, etc) is
> > transparent.
> >
> > The consumers should be responsible for avoiding the memory leaks and
> > this was an improvement of v2. Both MvGpioDxe and MvPca9xxxDxe have
> > now fixed error path an properly take care of freeing the memory after
> > using protocol.
>
> But the call sites don't keep track of freeing it when error handling.
>
> Which I think serves as a clear demonstrator of how magically
> allocating buffers makes for difficult code to keep correct. (Which is
> why the UEFI intefaces all require you to allocate a buffer and then
> pass that and a size as parameters.)
>
> So, since we are dealing with data that isn't changing, I prefer the
> original design - just not the original implemenation.
>
> So how about sticking with that, but moving the STATIC struct global
> in that source file (but keeping it STATIC)?
>

Good, keeping the global variable inside MvBoardDescDxe and checking
it there is a clean and easy solution (consumers won't have to bother
about the stuff additional to calling the protocol and error handling
will be simpler).

How about on top of the file I add a section for global varibles (IMO
it's worth to modify other interfaces to that scheme later) and call
it:

STATIC MV_BOARD_GPIO_DESCRIPTION gGpioDescription;
?

Thanks,
Marcin

> /
>     Leif
>
> > Please let know if above approach is acceptable.
> >
> > Best regards,
> > Marcin
> >
> > > /
> > >     Leif
> > >
> > > > +  if (Description == NULL) {
> > > > +    DEBUG ((DEBUG_ERROR, "%a: Cannot allocate memory\n", __FUNCTION__));
> > > > +    return EFI_OUT_OF_RESOURCES;
> > > > +  }
> > > > +
> > > > +  Description->SoCGpio = SoCGpio;
> > > > +  Description->GpioDeviceCount = SoCGpioCount;
> > > > +  Description->GpioExpanders = GpioExpanders;
> > > > +  Description->GpioExpanderCount = GpioExpanderCount;
> > > > +
> > > > +  *GpioDescription = Description;
> > > > +
> > > > +  return EFI_SUCCESS;
> > > > +}
> > > > +
> > > > +STATIC
> > > > +EFI_STATUS
> > > >  MvBoardDescI2cGet (
> > > >    IN MARVELL_BOARD_DESC_PROTOCOL  *This,
> > > >    IN OUT MV_BOARD_I2C_DESC       **I2cDesc
> > > > @@ -571,6 +613,7 @@ MvBoardDescInitProtocol (
> > > >    BoardDescProtocol->BoardDescUtmiGet = MvBoardDescUtmiGet;
> > > >    BoardDescProtocol->BoardDescXhciGet = MvBoardDescXhciGet;
> > > >    BoardDescProtocol->BoardDescFree = MvBoardDescFree;
> > > > +  BoardDescProtocol->GpioDescriptionGet = MvBoardGpioDescriptionGet;
> > > >
> > > >    return EFI_SUCCESS;
> > > >  }
> > > > --
> > > > 2.7.4
> > > >


  reply	other threads:[~2019-01-15 10:05 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-10  1:44 [platforms: PATCH v2 00/12] Armada 7k8k GPIO support Marcin Wojtas
2019-01-10  1:44 ` [platforms: PATCH v2 01/12] Marvell/Library: ArmadaSoCDescLib: Add GPIO information Marcin Wojtas
2019-01-14 23:45   ` Leif Lindholm
2019-01-10  1:44 ` [platforms: PATCH v2 02/12] Marvell/Library: ArmadaBoardDescLib: " Marcin Wojtas
2019-01-14 23:46   ` Leif Lindholm
2019-01-10  1:44 ` [platforms: PATCH v2 03/12] SolidRun/Armada80x0McBin: Extend board description library with GPIO Marcin Wojtas
2019-01-14 23:46   ` Leif Lindholm
2019-01-10  1:44 ` [platforms: PATCH v2 04/12] Marvell/Armada70x0Db: " Marcin Wojtas
2019-01-14 22:41   ` Leif Lindholm
2019-01-15  5:48     ` Marcin Wojtas
2019-01-10  1:44 ` [platforms: PATCH v2 05/12] Marvell/Armada80x0Db: " Marcin Wojtas
2019-01-14 22:44   ` Leif Lindholm
2019-01-10  1:44 ` [platforms: PATCH v2 06/12] Marvell/Drivers: MvBoardDesc: Extend protocol with GPIO support Marcin Wojtas
2019-01-14 22:58   ` Leif Lindholm
2019-01-15  6:05     ` Marcin Wojtas
2019-01-15  9:56       ` Leif Lindholm
2019-01-15 10:05         ` Marcin Wojtas [this message]
2019-01-15 10:12           ` Leif Lindholm
2019-01-15 10:14             ` Marcin Wojtas
2019-01-15 10:26               ` Leif Lindholm
2019-01-10  1:44 ` [platforms: PATCH v2 07/12] Marvell/Protocol: Introduce GPIO helper header Marcin Wojtas
2019-01-14 23:12   ` Leif Lindholm
2019-01-15  6:12     ` Marcin Wojtas
2019-01-10  1:44 ` [platforms: PATCH v2 08/12] Marvell/Drivers: MvGpioDxe: Introduce platform GPIO driver Marcin Wojtas
2019-01-14 23:32   ` Leif Lindholm
2019-01-15  6:19     ` Marcin Wojtas
2019-01-15 10:04       ` Leif Lindholm
2019-01-15 10:06         ` Marcin Wojtas
2019-01-10  1:44 ` [platforms: PATCH v2 09/12] Marvell/Drivers: I2c: Use common header for macros Marcin Wojtas
2019-01-10  1:44 ` [platforms: PATCH v2 10/12] Marvell/Drivers: MvPca95xxDxe: Introduce GPIO expander driver Marcin Wojtas
2019-01-14 23:40   ` Leif Lindholm
2019-01-10  1:44 ` [platforms: PATCH v2 11/12] Marvell/Armada7k8k: Enable GPIO drivers compilation Marcin Wojtas
2019-01-10  1:44 ` [platforms: PATCH v2 12/12] Marvell/Armada7k8k: Introduce NonDiscoverable device init routines Marcin Wojtas
2019-01-14 23:44   ` Leif Lindholm

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-list 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=CAPv3WKf73HjcEU2LzjutU8z+2dVh368n9CXpiOkkNB3xC+becQ@mail.gmail.com \
    --to=devel@edk2.groups.io \
    /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