linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] virtio, ring: Use ALIGN macros in virtio_ring.h
@ 2011-04-26  4:11 Liu Yuan
  2011-04-26  7:42 ` Michael S. Tsirkin
  0 siblings, 1 reply; 3+ messages in thread
From: Liu Yuan @ 2011-04-26  4:11 UTC (permalink / raw)
  To: Rusty Russell, Michael S. Tsirkin; +Cc: linux-kernel, virtualization

From: Liu Yuan <tailai.ly@taobao.com>


Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
---
 include/linux/virtio_ring.h |    8 +++-----
 1 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/include/linux/virtio_ring.h b/include/linux/virtio_ring.h
index e4d144b..6299050 100644
--- a/include/linux/virtio_ring.h
+++ b/include/linux/virtio_ring.h
@@ -99,15 +99,13 @@ static inline void vring_init(struct vring *vr, unsigned int num, void *p,
 	vr->num = num;
 	vr->desc = p;
 	vr->avail = p + num*sizeof(struct vring_desc);
-	vr->used = (void *)(((unsigned long)&vr->avail->ring[num] + align-1)
-			    & ~(align - 1));
+	vr->used = (void *)PTR_ALIGN(&vr->avail->ring[num], align);
 }
 
 static inline unsigned vring_size(unsigned int num, unsigned long align)
 {
-	return ((sizeof(struct vring_desc) * num + sizeof(__u16) * (2 + num)
-		 + align - 1) & ~(align - 1))
-		+ sizeof(__u16) * 2 + sizeof(struct vring_used_elem) * num;
+	return ((sizeof(struct vring_desc) * num + ALIGN(sizeof(__u16) * (2 + num), align))
+		+ sizeof(__u16) * 2 + sizeof(struct vring_used_elem) * num);
 }
 
 #ifdef __KERNEL__
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] virtio, ring: Use ALIGN macros in virtio_ring.h
  2011-04-26  4:11 [PATCH] virtio, ring: Use ALIGN macros in virtio_ring.h Liu Yuan
@ 2011-04-26  7:42 ` Michael S. Tsirkin
  2011-04-26  7:50   ` Liu Yuan
  0 siblings, 1 reply; 3+ messages in thread
From: Michael S. Tsirkin @ 2011-04-26  7:42 UTC (permalink / raw)
  To: Liu Yuan; +Cc: Rusty Russell, linux-kernel, virtualization

On Tue, Apr 26, 2011 at 12:11:10PM +0800, Liu Yuan wrote:
> From: Liu Yuan <tailai.ly@taobao.com>
> 
> 
> Signed-off-by: Liu Yuan <tailai.ly@taobao.com>

Issue is, these functions are exported to userspace,
which does not have these macros.

> ---
>  include/linux/virtio_ring.h |    8 +++-----
>  1 files changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/include/linux/virtio_ring.h b/include/linux/virtio_ring.h
> index e4d144b..6299050 100644
> --- a/include/linux/virtio_ring.h
> +++ b/include/linux/virtio_ring.h
> @@ -99,15 +99,13 @@ static inline void vring_init(struct vring *vr, unsigned int num, void *p,
>  	vr->num = num;
>  	vr->desc = p;
>  	vr->avail = p + num*sizeof(struct vring_desc);
> -	vr->used = (void *)(((unsigned long)&vr->avail->ring[num] + align-1)
> -			    & ~(align - 1));
> +	vr->used = (void *)PTR_ALIGN(&vr->avail->ring[num], align);
>  }
>  
>  static inline unsigned vring_size(unsigned int num, unsigned long align)
>  {
> -	return ((sizeof(struct vring_desc) * num + sizeof(__u16) * (2 + num)
> -		 + align - 1) & ~(align - 1))
> -		+ sizeof(__u16) * 2 + sizeof(struct vring_used_elem) * num;
> +	return ((sizeof(struct vring_desc) * num + ALIGN(sizeof(__u16) * (2 + num), align))
> +		+ sizeof(__u16) * 2 + sizeof(struct vring_used_elem) * num);
>  }
>  
>  #ifdef __KERNEL__
> -- 
> 1.7.1

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] virtio, ring: Use ALIGN macros in virtio_ring.h
  2011-04-26  7:42 ` Michael S. Tsirkin
@ 2011-04-26  7:50   ` Liu Yuan
  0 siblings, 0 replies; 3+ messages in thread
From: Liu Yuan @ 2011-04-26  7:50 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: Rusty Russell, linux-kernel, virtualization

On 04/26/2011 03:42 PM, Michael S. Tsirkin wrote:
> On Tue, Apr 26, 2011 at 12:11:10PM +0800, Liu Yuan wrote:
>> From: Liu Yuan<tailai.ly@taobao.com>
>>
>>
>> Signed-off-by: Liu Yuan<tailai.ly@taobao.com>
> Issue is, these functions are exported to userspace,
> which does not have these macros.
>
Ah, thanks, I should have noticed the '#ifdef __KERNEL__' just below the 
lines I touched.

Thanks,
Yuan

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-04-26  7:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-26  4:11 [PATCH] virtio, ring: Use ALIGN macros in virtio_ring.h Liu Yuan
2011-04-26  7:42 ` Michael S. Tsirkin
2011-04-26  7:50   ` Liu Yuan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).