linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [Outreachy][PATCH] drm: use DIV_ROUND_UP helper macro for calculations
@ 2019-10-25  9:49 Wambui Karuga
  2019-10-25 10:12 ` [Outreachy kernel] " Julia Lawall
  0 siblings, 1 reply; 3+ messages in thread
From: Wambui Karuga @ 2019-10-25  9:49 UTC (permalink / raw)
  To: dri-devel
  Cc: maarten.lankhorst, mripard, sean, airlied, daniel, linux-kernel,
	outreachy-kernel

Replace open coded divisor calculations with the DIV_ROUND_UP kernel
macro for better readability.
Issue found using coccinelle:
@@
expression n,d;
@@
(
- ((n + d - 1) / d)
+ DIV_ROUND_UP(n,d)
|
- ((n + (d - 1)) / d)
+ DIV_ROUND_UP(n,d)
)

Signed-off-by: Wambui Karuga <wambui.karugax@gmail.com>
---
 drivers/gpu/drm/drm_agpsupport.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/drm_agpsupport.c b/drivers/gpu/drm/drm_agpsupport.c
index 6e09f27fd9d6..4c7ad46fdd21 100644
--- a/drivers/gpu/drm/drm_agpsupport.c
+++ b/drivers/gpu/drm/drm_agpsupport.c
@@ -212,7 +212,7 @@ int drm_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request)
 	if (!entry)
 		return -ENOMEM;
 
-	pages = (request->size + PAGE_SIZE - 1) / PAGE_SIZE;
+	pages = DIV_ROUND_UP(request->size, PAGE_SIZE);
 	type = (u32) request->type;
 	memory = agp_allocate_memory(dev->agp->bridge, pages, type);
 	if (!memory) {
@@ -325,7 +325,7 @@ int drm_agp_bind(struct drm_device *dev, struct drm_agp_binding *request)
 	entry = drm_agp_lookup_entry(dev, request->handle);
 	if (!entry || entry->bound)
 		return -EINVAL;
-	page = (request->offset + PAGE_SIZE - 1) / PAGE_SIZE;
+	page = DIV_ROUND_UP(request->offset, PAGE_SIZE);
 	retcode = drm_bind_agp(entry->memory, page);
 	if (retcode)
 		return retcode;
-- 
2.23.0


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

* Re: [Outreachy kernel] [Outreachy][PATCH] drm: use DIV_ROUND_UP helper macro for calculations
  2019-10-25  9:49 [Outreachy][PATCH] drm: use DIV_ROUND_UP helper macro for calculations Wambui Karuga
@ 2019-10-25 10:12 ` Julia Lawall
  2019-10-25 19:40   ` Daniel Vetter
  0 siblings, 1 reply; 3+ messages in thread
From: Julia Lawall @ 2019-10-25 10:12 UTC (permalink / raw)
  To: Wambui Karuga
  Cc: dri-devel, maarten.lankhorst, mripard, sean, airlied, daniel,
	linux-kernel, outreachy-kernel



On Fri, 25 Oct 2019, Wambui Karuga wrote:

> Replace open coded divisor calculations with the DIV_ROUND_UP kernel
> macro for better readability.
> Issue found using coccinelle:
> @@
> expression n,d;
> @@
> (
> - ((n + d - 1) / d)
> + DIV_ROUND_UP(n,d)
> |
> - ((n + (d - 1)) / d)
> + DIV_ROUND_UP(n,d)
> )
>
> Signed-off-by: Wambui Karuga <wambui.karugax@gmail.com>

Acked-by: Julia Lawall <julia.lawall@lip6.fr>


> ---
>  drivers/gpu/drm/drm_agpsupport.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_agpsupport.c b/drivers/gpu/drm/drm_agpsupport.c
> index 6e09f27fd9d6..4c7ad46fdd21 100644
> --- a/drivers/gpu/drm/drm_agpsupport.c
> +++ b/drivers/gpu/drm/drm_agpsupport.c
> @@ -212,7 +212,7 @@ int drm_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request)
>  	if (!entry)
>  		return -ENOMEM;
>
> -	pages = (request->size + PAGE_SIZE - 1) / PAGE_SIZE;
> +	pages = DIV_ROUND_UP(request->size, PAGE_SIZE);
>  	type = (u32) request->type;
>  	memory = agp_allocate_memory(dev->agp->bridge, pages, type);
>  	if (!memory) {
> @@ -325,7 +325,7 @@ int drm_agp_bind(struct drm_device *dev, struct drm_agp_binding *request)
>  	entry = drm_agp_lookup_entry(dev, request->handle);
>  	if (!entry || entry->bound)
>  		return -EINVAL;
> -	page = (request->offset + PAGE_SIZE - 1) / PAGE_SIZE;
> +	page = DIV_ROUND_UP(request->offset, PAGE_SIZE);
>  	retcode = drm_bind_agp(entry->memory, page);
>  	if (retcode)
>  		return retcode;
> --
> 2.23.0
>
> --
> You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to outreachy-kernel+unsubscribe@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20191025094907.3582-1-wambui.karugax%40gmail.com.
>

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

* Re: [Outreachy kernel] [Outreachy][PATCH] drm: use DIV_ROUND_UP helper macro for calculations
  2019-10-25 10:12 ` [Outreachy kernel] " Julia Lawall
@ 2019-10-25 19:40   ` Daniel Vetter
  0 siblings, 0 replies; 3+ messages in thread
From: Daniel Vetter @ 2019-10-25 19:40 UTC (permalink / raw)
  To: Julia Lawall
  Cc: Wambui Karuga, dri-devel, maarten.lankhorst, mripard, sean,
	airlied, daniel, linux-kernel, outreachy-kernel

On Fri, Oct 25, 2019 at 12:12:23PM +0200, Julia Lawall wrote:
> 
> 
> On Fri, 25 Oct 2019, Wambui Karuga wrote:
> 
> > Replace open coded divisor calculations with the DIV_ROUND_UP kernel
> > macro for better readability.
> > Issue found using coccinelle:
> > @@
> > expression n,d;
> > @@
> > (
> > - ((n + d - 1) / d)
> > + DIV_ROUND_UP(n,d)
> > |
> > - ((n + (d - 1)) / d)
> > + DIV_ROUND_UP(n,d)
> > )
> >
> > Signed-off-by: Wambui Karuga <wambui.karugax@gmail.com>
> 
> Acked-by: Julia Lawall <julia.lawall@lip6.fr>

Applied to drm-misc-next, thanks for your patch.
-Daniel

> 
> 
> > ---
> >  drivers/gpu/drm/drm_agpsupport.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/drm_agpsupport.c b/drivers/gpu/drm/drm_agpsupport.c
> > index 6e09f27fd9d6..4c7ad46fdd21 100644
> > --- a/drivers/gpu/drm/drm_agpsupport.c
> > +++ b/drivers/gpu/drm/drm_agpsupport.c
> > @@ -212,7 +212,7 @@ int drm_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request)
> >  	if (!entry)
> >  		return -ENOMEM;
> >
> > -	pages = (request->size + PAGE_SIZE - 1) / PAGE_SIZE;
> > +	pages = DIV_ROUND_UP(request->size, PAGE_SIZE);
> >  	type = (u32) request->type;
> >  	memory = agp_allocate_memory(dev->agp->bridge, pages, type);
> >  	if (!memory) {
> > @@ -325,7 +325,7 @@ int drm_agp_bind(struct drm_device *dev, struct drm_agp_binding *request)
> >  	entry = drm_agp_lookup_entry(dev, request->handle);
> >  	if (!entry || entry->bound)
> >  		return -EINVAL;
> > -	page = (request->offset + PAGE_SIZE - 1) / PAGE_SIZE;
> > +	page = DIV_ROUND_UP(request->offset, PAGE_SIZE);
> >  	retcode = drm_bind_agp(entry->memory, page);
> >  	if (retcode)
> >  		return retcode;
> > --
> > 2.23.0
> >
> > --
> > You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
> > To unsubscribe from this group and stop receiving emails from it, send an email to outreachy-kernel+unsubscribe@googlegroups.com.
> > To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20191025094907.3582-1-wambui.karugax%40gmail.com.
> >

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

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

end of thread, other threads:[~2019-10-25 19:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-25  9:49 [Outreachy][PATCH] drm: use DIV_ROUND_UP helper macro for calculations Wambui Karuga
2019-10-25 10:12 ` [Outreachy kernel] " Julia Lawall
2019-10-25 19:40   ` Daniel Vetter

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).