diff mbox

[V2,1/4] libflash/mbox-flash: Minor fixups before V2

Message ID 20170524063719.5619-2-sjitindarsingh@gmail.com
State Accepted
Headers show

Commit Message

Suraj Jitindar Singh May 24, 2017, 6:37 a.m. UTC
From: Cyril Bur <cyril.bur@au1.ibm.com>

- Warn if flushing with closed write window.
- Call msg_free_memory() in mbox_flash_init() before a successful
  return. No leak is present as the current allocation theme is from
  static memory. However as this is likely to change in the future,
  best to ensure that msg_free_memory() is called after every
  allocation.
- Fix bug where len argument may be incorrect in mark dirty command.

Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com>
Signed-off-by: Suraj Jitindar Singh <sjitindarsingh@gmail.com>

---

V1 -> V2:

- Fix bug where len argument may be incorrect in mark dirty command.
---
 libflash/mbox-flash.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Comments

Andrew Jeffery May 25, 2017, 1:19 a.m. UTC | #1
On Wed, 2017-05-24 at 16:37 +1000, Suraj Jitindar Singh wrote:
> > From: Cyril Bur <cyril.bur@au1.ibm.com>
> 
> - Warn if flushing with closed write window.
> - Call msg_free_memory() in mbox_flash_init() before a successful
>   return. No leak is present as the current allocation theme is from
>   static memory. However as this is likely to change in the future,
>   best to ensure that msg_free_memory() is called after every
>   allocation.
> - Fix bug where len argument may be incorrect in mark dirty command.
> 
> > Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com>
> Signed-off-by: Suraj Jitindar Singh <sjitindarsingh@gmail.com>

My lack of skiboot reputation not withstanding:

Reviewed-by: Andrew Jeffery <andrew@aj.id.au>

> 
> ---
> 
> V1 -> V2:
> 
> - Fix bug where len argument may be incorrect in mark dirty command.
> ---
>  libflash/mbox-flash.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/libflash/mbox-flash.c b/libflash/mbox-flash.c
> index 7bf731d..996e471 100644
> --- a/libflash/mbox-flash.c
> +++ b/libflash/mbox-flash.c
> @@ -228,14 +228,18 @@ static int lpc_window_write(struct mbox_flash_data *mbox_flash, uint32_t pos,
>  static int mbox_flash_flush(struct mbox_flash_data *mbox_flash, uint64_t pos,
> >  		uint64_t len)
>  {
> > +	uint32_t start = ALIGN_DOWN(pos, 1 << mbox_flash->shift);
> >  	struct bmc_mbox_msg *msg;
> >  	int rc;
>  
> > +	if (!mbox_flash->write.open)
> > +		prlog(PR_WARNING, "Attempting to flush without an open write window\n");
> +
> >  	msg = msg_alloc(mbox_flash, MBOX_C_WRITE_FLUSH);
> >  	if (!msg)
> >  		return FLASH_ERR_MALLOC_FAILED;
> >  	msg_put_u16(msg, 0, pos >> mbox_flash->shift);
> > -	msg_put_u32(msg, 2, len);
> > +	msg_put_u32(msg, 2, pos + len - start);
>  
> >  	rc = msg_send(mbox_flash, msg);
> >  	if (rc) {
> @@ -550,6 +554,8 @@ int mbox_flash_init(struct blocklevel_device **bl)
> >  		goto out_msg;
> >  	}
>  
> > +	msg_free_memory(msg);
> +
> >  	mbox_flash->bl.keep_alive = 0;
> >  	mbox_flash->bl.read = &mbox_flash_read;
> >  	mbox_flash->bl.write = &mbox_flash_write;
Cyril Bur May 26, 2017, 4:09 a.m. UTC | #2
On Wed, 2017-05-24 at 16:37 +1000, Suraj Jitindar Singh wrote:
> From: Cyril Bur <cyril.bur@au1.ibm.com>
> 
> - Warn if flushing with closed write window.
> - Call msg_free_memory() in mbox_flash_init() before a successful
>   return. No leak is present as the current allocation theme is from
>   static memory. However as this is likely to change in the future,
>   best to ensure that msg_free_memory() is called after every
>   allocation.
> - Fix bug where len argument may be incorrect in mark dirty command.
> 
> Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com>
> Signed-off-by: Suraj Jitindar Singh <sjitindarsingh@gmail.com>

Acked-by: Cyril Bur <cyri.bur@au1.ibm.com>

> 
> ---
> 
> V1 -> V2:
> 
> - Fix bug where len argument may be incorrect in mark dirty command.
> ---
>  libflash/mbox-flash.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/libflash/mbox-flash.c b/libflash/mbox-flash.c
> index 7bf731d..996e471 100644
> --- a/libflash/mbox-flash.c
> +++ b/libflash/mbox-flash.c
> @@ -228,14 +228,18 @@ static int lpc_window_write(struct mbox_flash_data *mbox_flash, uint32_t pos,
>  static int mbox_flash_flush(struct mbox_flash_data *mbox_flash, uint64_t pos,
>  		uint64_t len)
>  {
> +	uint32_t start = ALIGN_DOWN(pos, 1 << mbox_flash->shift);
>  	struct bmc_mbox_msg *msg;
>  	int rc;
>  
> +	if (!mbox_flash->write.open)
> +		prlog(PR_WARNING, "Attempting to flush without an open write window\n");
> +
>  	msg = msg_alloc(mbox_flash, MBOX_C_WRITE_FLUSH);
>  	if (!msg)
>  		return FLASH_ERR_MALLOC_FAILED;
>  	msg_put_u16(msg, 0, pos >> mbox_flash->shift);
> -	msg_put_u32(msg, 2, len);
> +	msg_put_u32(msg, 2, pos + len - start);
>  
>  	rc = msg_send(mbox_flash, msg);
>  	if (rc) {
> @@ -550,6 +554,8 @@ int mbox_flash_init(struct blocklevel_device **bl)
>  		goto out_msg;
>  	}
>  
> +	msg_free_memory(msg);
> +
>  	mbox_flash->bl.keep_alive = 0;
>  	mbox_flash->bl.read = &mbox_flash_read;
>  	mbox_flash->bl.write = &mbox_flash_write;
diff mbox

Patch

diff --git a/libflash/mbox-flash.c b/libflash/mbox-flash.c
index 7bf731d..996e471 100644
--- a/libflash/mbox-flash.c
+++ b/libflash/mbox-flash.c
@@ -228,14 +228,18 @@  static int lpc_window_write(struct mbox_flash_data *mbox_flash, uint32_t pos,
 static int mbox_flash_flush(struct mbox_flash_data *mbox_flash, uint64_t pos,
 		uint64_t len)
 {
+	uint32_t start = ALIGN_DOWN(pos, 1 << mbox_flash->shift);
 	struct bmc_mbox_msg *msg;
 	int rc;
 
+	if (!mbox_flash->write.open)
+		prlog(PR_WARNING, "Attempting to flush without an open write window\n");
+
 	msg = msg_alloc(mbox_flash, MBOX_C_WRITE_FLUSH);
 	if (!msg)
 		return FLASH_ERR_MALLOC_FAILED;
 	msg_put_u16(msg, 0, pos >> mbox_flash->shift);
-	msg_put_u32(msg, 2, len);
+	msg_put_u32(msg, 2, pos + len - start);
 
 	rc = msg_send(mbox_flash, msg);
 	if (rc) {
@@ -550,6 +554,8 @@  int mbox_flash_init(struct blocklevel_device **bl)
 		goto out_msg;
 	}
 
+	msg_free_memory(msg);
+
 	mbox_flash->bl.keep_alive = 0;
 	mbox_flash->bl.read = &mbox_flash_read;
 	mbox_flash->bl.write = &mbox_flash_write;