diff mbox series

[1/1] lib: simplify sbi_fifo_inplace_update()

Message ID 20210621190316.25463-1-xypron.glpk@gmx.de
State Accepted
Headers show
Series [1/1] lib: simplify sbi_fifo_inplace_update() | expand

Commit Message

Heinrich Schuchardt June 21, 2021, 7:03 p.m. UTC
Don't assign an unused value to variable index.

Use operator '-=' where applicable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
 lib/sbi/sbi_fifo.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

--
2.30.2

Comments

Atish Patra June 21, 2021, 8:01 p.m. UTC | #1
On Mon, Jun 21, 2021 at 12:03 PM Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
>
> Don't assign an unused value to variable index.
>
> Use operator '-=' where applicable.
>
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> ---
>  lib/sbi/sbi_fifo.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/lib/sbi/sbi_fifo.c b/lib/sbi/sbi_fifo.c
> index 2a5c012..b2395f3 100644
> --- a/lib/sbi/sbi_fifo.c
> +++ b/lib/sbi/sbi_fifo.c
> @@ -118,7 +118,7 @@ bool sbi_fifo_reset(struct sbi_fifo *fifo)
>  int sbi_fifo_inplace_update(struct sbi_fifo *fifo, void *in,
>                             int (*fptr)(void *in, void *data))
>  {
> -       int i, index = 0;
> +       int i, index;
>         int ret = SBI_FIFO_UNCHANGED;
>         void *entry;
>
> @@ -135,7 +135,7 @@ int sbi_fifo_inplace_update(struct sbi_fifo *fifo, void *in,
>         for (i = 0; i < fifo->avail; i++) {
>                 index = fifo->tail + i;
>                 if (index >= fifo->num_entries)
> -                       index = index - fifo->num_entries;
> +                       index -= fifo->num_entries;
>                 entry = (void *)fifo->queue + (u32)index * fifo->entry_size;
>                 ret = fptr(in, entry);
>
> --
> 2.30.2
>
>
> --
> opensbi mailing list
> opensbi@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/opensbi


Reviewed-by: Atish Patra <atish.patra@wdc.com>
Xiang W June 22, 2021, 6:44 a.m. UTC | #2
在 2021-06-21星期一的 21:03 +0200,Heinrich Schuchardt写道:
> Don't assign an unused value to variable index.
> 
> Use operator '-=' where applicable.
> 
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Xiang W <wxjstz@126.com>

Regards,
Xiang W
> ---
>  lib/sbi/sbi_fifo.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/sbi/sbi_fifo.c b/lib/sbi/sbi_fifo.c
> index 2a5c012..b2395f3 100644
> --- a/lib/sbi/sbi_fifo.c
> +++ b/lib/sbi/sbi_fifo.c
> @@ -118,7 +118,7 @@ bool sbi_fifo_reset(struct sbi_fifo *fifo)
>  int sbi_fifo_inplace_update(struct sbi_fifo *fifo, void *in,
>                             int (*fptr)(void *in, void *data))
>  {
> -       int i, index = 0;
> +       int i, index;
>         int ret = SBI_FIFO_UNCHANGED;
>         void *entry;
> 
> @@ -135,7 +135,7 @@ int sbi_fifo_inplace_update(struct sbi_fifo
> *fifo, void *in,
>         for (i = 0; i < fifo->avail; i++) {
>                 index = fifo->tail + i;
>                 if (index >= fifo->num_entries)
> -                       index = index - fifo->num_entries;
> +                       index -= fifo->num_entries;
>                 entry = (void *)fifo->queue + (u32)index * fifo-
> >entry_size;
>                 ret = fptr(in, entry);
> 
> --
> 2.30.2
> 
>
Anup Patel June 22, 2021, 3:02 p.m. UTC | #3
On 22/06/21, 12:14 PM, "opensbi on behalf of Xiang W" <opensbi-bounces@lists.infradead.org on behalf of wxjstz@126.com> wrote:

    在 2021-06-21星期一的 21:03 +0200,Heinrich Schuchardt写道:
    > Don't assign an unused value to variable index.
    > 
    > Use operator '-=' where applicable.
    > 
    > Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
    Reviewed-by: Xiang W <wxjstz@126.com>

Applied this patch to the riscv/opensbi repo.

Regards,
Anup

    > ---
    >  lib/sbi/sbi_fifo.c | 4 ++--
    >  1 file changed, 2 insertions(+), 2 deletions(-)
    > 
    > diff --git a/lib/sbi/sbi_fifo.c b/lib/sbi/sbi_fifo.c
    > index 2a5c012..b2395f3 100644
    > --- a/lib/sbi/sbi_fifo.c
    > +++ b/lib/sbi/sbi_fifo.c
    > @@ -118,7 +118,7 @@ bool sbi_fifo_reset(struct sbi_fifo *fifo)
    >  int sbi_fifo_inplace_update(struct sbi_fifo *fifo, void *in,
    >                             int (*fptr)(void *in, void *data))
    >  {
    > -       int i, index = 0;
    > +       int i, index;
    >         int ret = SBI_FIFO_UNCHANGED;
    >         void *entry;
    > 
    > @@ -135,7 +135,7 @@ int sbi_fifo_inplace_update(struct sbi_fifo
    > *fifo, void *in,
    >         for (i = 0; i < fifo->avail; i++) {
    >                 index = fifo->tail + i;
    >                 if (index >= fifo->num_entries)
    > -                       index = index - fifo->num_entries;
    > +                       index -= fifo->num_entries;
    >                 entry = (void *)fifo->queue + (u32)index * fifo-
    > >entry_size;
    >                 ret = fptr(in, entry);
    > 
    > --
    > 2.30.2
    > 
    > 



    -- 
    opensbi mailing list
    opensbi@lists.infradead.org
    http://lists.infradead.org/mailman/listinfo/opensbi
diff mbox series

Patch

diff --git a/lib/sbi/sbi_fifo.c b/lib/sbi/sbi_fifo.c
index 2a5c012..b2395f3 100644
--- a/lib/sbi/sbi_fifo.c
+++ b/lib/sbi/sbi_fifo.c
@@ -118,7 +118,7 @@  bool sbi_fifo_reset(struct sbi_fifo *fifo)
 int sbi_fifo_inplace_update(struct sbi_fifo *fifo, void *in,
 			    int (*fptr)(void *in, void *data))
 {
-	int i, index = 0;
+	int i, index;
 	int ret = SBI_FIFO_UNCHANGED;
 	void *entry;

@@ -135,7 +135,7 @@  int sbi_fifo_inplace_update(struct sbi_fifo *fifo, void *in,
 	for (i = 0; i < fifo->avail; i++) {
 		index = fifo->tail + i;
 		if (index >= fifo->num_entries)
-			index = index - fifo->num_entries;
+			index -= fifo->num_entries;
 		entry = (void *)fifo->queue + (u32)index * fifo->entry_size;
 		ret = fptr(in, entry);