[Qemu-devel] [PATCH v3 09/16] s390-bios: ptr2u32 and u32toptr

Jason J. Herne posted 16 patches 6 years, 11 months ago
Maintainers: Eric Farman <farman@linux.ibm.com>, Thomas Huth <thuth@redhat.com>, Laurent Vivier <lvivier@redhat.com>, Cornelia Huck <cohuck@redhat.com>, Richard Henderson <rth@twiddle.net>, Christian Borntraeger <borntraeger@de.ibm.com>, David Hildenbrand <david@redhat.com>, Halil Pasic <pasic@linux.ibm.com>, Farhan Ali <alifm@linux.ibm.com>, Paolo Bonzini <pbonzini@redhat.com>, Alex Williamson <alex.williamson@redhat.com>
There is a newer version of this series
[Qemu-devel] [PATCH v3 09/16] s390-bios: ptr2u32 and u32toptr
Posted by Jason J. Herne 6 years, 11 months ago
Introduce inline functions to convert between pointers and unsigned 32-bit
ints. These are used to hide the ugliness required to  avoid compiler
warnings.

Signed-off-by: Jason J. Herne <jjherne@linux.ibm.com>
Acked-by: Cornelia Huck <cohuck@redhat.com>
---
 pc-bios/s390-ccw/helper.h | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
 create mode 100644 pc-bios/s390-ccw/helper.h

diff --git a/pc-bios/s390-ccw/helper.h b/pc-bios/s390-ccw/helper.h
new file mode 100644
index 0000000..b8bc61b
--- /dev/null
+++ b/pc-bios/s390-ccw/helper.h
@@ -0,0 +1,16 @@
+#ifndef S390_CCW_HELPER_H
+#define S390_CCW_HELPER_H
+
+/* Avoids compiler warnings when casting a pointer to a u32 */
+static inline uint32_t ptr2u32(void *ptr)
+{
+    return (uint32_t)(uint64_t)ptr;
+}
+
+/* Avoids compiler warnings when casting a u32 to a pointer */
+static inline void *u32toptr(uint32_t n)
+{
+    return (void *)(uint64_t)n;
+}
+
+#endif
-- 
2.7.4


Re: [Qemu-devel] [qemu-s390x] [PATCH v3 09/16] s390-bios: ptr2u32 and u32toptr
Posted by Thomas Huth 6 years, 11 months ago
On 01/03/2019 19.59, Jason J. Herne wrote:
> Introduce inline functions to convert between pointers and unsigned 32-bit
> ints. These are used to hide the ugliness required to  avoid compiler
> warnings.
> 
> Signed-off-by: Jason J. Herne <jjherne@linux.ibm.com>
> Acked-by: Cornelia Huck <cohuck@redhat.com>
> ---
>  pc-bios/s390-ccw/helper.h | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
>  create mode 100644 pc-bios/s390-ccw/helper.h
> 
> diff --git a/pc-bios/s390-ccw/helper.h b/pc-bios/s390-ccw/helper.h
> new file mode 100644
> index 0000000..b8bc61b
> --- /dev/null
> +++ b/pc-bios/s390-ccw/helper.h
> @@ -0,0 +1,16 @@
> +#ifndef S390_CCW_HELPER_H
> +#define S390_CCW_HELPER_H
> +
> +/* Avoids compiler warnings when casting a pointer to a u32 */
> +static inline uint32_t ptr2u32(void *ptr)
> +{

Would it make sense to add an IPL_assert(ptr <= 0xffffffff) here?

> +    return (uint32_t)(uint64_t)ptr;
> +}
> +
> +/* Avoids compiler warnings when casting a u32 to a pointer */
> +static inline void *u32toptr(uint32_t n)
> +{
> +    return (void *)(uint64_t)n;
> +}
> +
> +#endif

Reviewed-by: Thomas Huth <thuth@redhat.com>

Re: [Qemu-devel] [qemu-s390x] [PATCH v3 09/16] s390-bios: ptr2u32 and u32toptr
Posted by Jason J. Herne 6 years, 11 months ago
On 3/5/19 2:22 AM, Thomas Huth wrote:
> On 01/03/2019 19.59, Jason J. Herne wrote:
>> Introduce inline functions to convert between pointers and unsigned 32-bit
>> ints. These are used to hide the ugliness required to  avoid compiler
>> warnings.
>>
>> Signed-off-by: Jason J. Herne <jjherne@linux.ibm.com>
>> Acked-by: Cornelia Huck <cohuck@redhat.com>
>> ---
>>   pc-bios/s390-ccw/helper.h | 16 ++++++++++++++++
>>   1 file changed, 16 insertions(+)
>>   create mode 100644 pc-bios/s390-ccw/helper.h
>>
>> diff --git a/pc-bios/s390-ccw/helper.h b/pc-bios/s390-ccw/helper.h
>> new file mode 100644
>> index 0000000..b8bc61b
>> --- /dev/null
>> +++ b/pc-bios/s390-ccw/helper.h
>> @@ -0,0 +1,16 @@
>> +#ifndef S390_CCW_HELPER_H
>> +#define S390_CCW_HELPER_H
>> +
>> +/* Avoids compiler warnings when casting a pointer to a u32 */
>> +static inline uint32_t ptr2u32(void *ptr)
>> +{
> 
> Would it make sense to add an IPL_assert(ptr <= 0xffffffff) here?
> 

I'm not sure... I remember something about the bios always having to be below the 2^32 
memory line. But I suppose it doesn't hurt to add the assert anyway. Then, someday, if my 
assumption proves not to be true or someone changes that assumption we are still covered.

-- 
-- Jason J. Herne (jjherne@linux.ibm.com)