diff mbox

include: Add roundup_pow_of_two helper function

Message ID 1480317522-5950-1-git-send-email-yuval.shaia@oracle.com
State New
Headers show

Commit Message

Yuval Shaia Nov. 28, 2016, 7:18 a.m. UTC
Move private implementation of rthe function to osdep.h

Signed-off-by: Yuval Shaia <yuval.shaia@oracle.com>
---
 hw/pci/shpc.c        | 12 +-----------
 include/qemu/osdep.h | 10 ++++++++++
 2 files changed, 11 insertions(+), 11 deletions(-)

Comments

Marcel Apfelbaum Nov. 28, 2016, 12:08 p.m. UTC | #1
On 11/28/2016 09:18 AM, Yuval Shaia wrote:
> Move private implementation of rthe function to osdep.h

Hi Yuval,

In my opinion we need to use the function in at least
two places in order to promote it to a global utility.

You are welcome to try to find another place needing it.

Thanks,
Marcel

>
> Signed-off-by: Yuval Shaia <yuval.shaia@oracle.com>
> ---
>  hw/pci/shpc.c        | 12 +-----------
>  include/qemu/osdep.h | 10 ++++++++++
>  2 files changed, 11 insertions(+), 11 deletions(-)
>
> diff --git a/hw/pci/shpc.c b/hw/pci/shpc.c
> index 3dcd472..4b8982d 100644
> --- a/hw/pci/shpc.c
> +++ b/hw/pci/shpc.c
> @@ -122,16 +122,6 @@
>  #define SHPC_PCI_TO_IDX(pci_slot) ((pci_slot) - 1)
>  #define SHPC_IDX_TO_PHYSICAL(slot) ((slot) + 1)
>
> -static int roundup_pow_of_two(int x)
> -{
> -    x |= (x >> 1);
> -    x |= (x >> 2);
> -    x |= (x >> 4);
> -    x |= (x >> 8);
> -    x |= (x >> 16);
> -    return x + 1;
> -}
> -
>  static uint16_t shpc_get_status(SHPCDevice *shpc, int slot, uint16_t msk)
>  {
>      uint8_t *status = shpc->config + SHPC_SLOT_STATUS(slot);
> @@ -654,7 +644,7 @@ int shpc_init(PCIDevice *d, PCIBus *sec_bus, MemoryRegion *bar, unsigned offset)
>
>  int shpc_bar_size(PCIDevice *d)
>  {
> -    return roundup_pow_of_two(SHPC_SLOT_REG(SHPC_MAX_SLOTS));
> +    return round_up_pow_of_two(SHPC_SLOT_REG(SHPC_MAX_SLOTS));
>  }
>
>  void shpc_cleanup(PCIDevice *d, MemoryRegion *bar)
> diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
> index 689f253..74d5c30 100644
> --- a/include/qemu/osdep.h
> +++ b/include/qemu/osdep.h
> @@ -194,6 +194,16 @@ extern int daemon(int, int);
>  #define ROUND_UP(n,d) (((n) + (d) - 1) & -(d))
>  #endif
>
> +static inline int round_up_pow_of_two(int x)
> +{
> +	x |= (x >> 1);
> +	x |= (x >> 2);
> +	x |= (x >> 4);
> +	x |= (x >> 8);
> +	x |= (x >> 16);
> +	return x + 1;
> +}
> +
>  #ifndef DIV_ROUND_UP
>  #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
>  #endif
>
no-reply@patchew.org Nov. 29, 2016, 1:28 p.m. UTC | #2
Hi,

Your series seems to have some coding style problems. See output below for
more information:

Subject: [Qemu-devel] [PATCH] include: Add roundup_pow_of_two helper function
Type: series
Message-id: 1480317522-5950-1-git-send-email-yuval.shaia@oracle.com

=== TEST SCRIPT BEGIN ===
#!/bin/bash

BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0

# Useful git options
git config --local diff.renamelimit 0
git config --local diff.renames True

commits="$(git log --format=%H --reverse $BASE..)"
for c in $commits; do
    echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
    if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
        failed=1
        echo
    fi
    n=$((n+1))
done

exit $failed
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
Switched to a new branch 'test'
61b93c6 include: Add roundup_pow_of_two helper function

=== OUTPUT BEGIN ===
Checking PATCH 1/1: include: Add roundup_pow_of_two helper function...
ERROR: code indent should never use tabs
#51: FILE: include/qemu/osdep.h:199:
+^Ix |= (x >> 1);$

ERROR: code indent should never use tabs
#52: FILE: include/qemu/osdep.h:200:
+^Ix |= (x >> 2);$

ERROR: code indent should never use tabs
#53: FILE: include/qemu/osdep.h:201:
+^Ix |= (x >> 4);$

ERROR: code indent should never use tabs
#54: FILE: include/qemu/osdep.h:202:
+^Ix |= (x >> 8);$

ERROR: code indent should never use tabs
#55: FILE: include/qemu/osdep.h:203:
+^Ix |= (x >> 16);$

ERROR: code indent should never use tabs
#56: FILE: include/qemu/osdep.h:204:
+^Ireturn x + 1;$

total: 6 errors, 0 warnings, 40 lines checked

Your patch has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

=== OUTPUT END ===

Test command exited with code: 1


---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to patchew-devel@freelists.org
diff mbox

Patch

diff --git a/hw/pci/shpc.c b/hw/pci/shpc.c
index 3dcd472..4b8982d 100644
--- a/hw/pci/shpc.c
+++ b/hw/pci/shpc.c
@@ -122,16 +122,6 @@ 
 #define SHPC_PCI_TO_IDX(pci_slot) ((pci_slot) - 1)
 #define SHPC_IDX_TO_PHYSICAL(slot) ((slot) + 1)
 
-static int roundup_pow_of_two(int x)
-{
-    x |= (x >> 1);
-    x |= (x >> 2);
-    x |= (x >> 4);
-    x |= (x >> 8);
-    x |= (x >> 16);
-    return x + 1;
-}
-
 static uint16_t shpc_get_status(SHPCDevice *shpc, int slot, uint16_t msk)
 {
     uint8_t *status = shpc->config + SHPC_SLOT_STATUS(slot);
@@ -654,7 +644,7 @@  int shpc_init(PCIDevice *d, PCIBus *sec_bus, MemoryRegion *bar, unsigned offset)
 
 int shpc_bar_size(PCIDevice *d)
 {
-    return roundup_pow_of_two(SHPC_SLOT_REG(SHPC_MAX_SLOTS));
+    return round_up_pow_of_two(SHPC_SLOT_REG(SHPC_MAX_SLOTS));
 }
 
 void shpc_cleanup(PCIDevice *d, MemoryRegion *bar)
diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index 689f253..74d5c30 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -194,6 +194,16 @@  extern int daemon(int, int);
 #define ROUND_UP(n,d) (((n) + (d) - 1) & -(d))
 #endif
 
+static inline int round_up_pow_of_two(int x)
+{
+	x |= (x >> 1);
+	x |= (x >> 2);
+	x |= (x >> 4);
+	x |= (x >> 8);
+	x |= (x >> 16);
+	return x + 1;
+}
+
 #ifndef DIV_ROUND_UP
 #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
 #endif