Skip to contentSkip to conversation

Staging: media: davinci_vpfe: Convert ceil macro into an inline function

PATCH Superseded Madhumitha Prabakaran 2 participants 5 messages Mar 27, 2019 – Apr 2, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Staging: media: davinci_vpfe: Convert ceil macro into an inline function

Convert macro into an inline function in order to maintain Linux kernel coding style based on which the inline function is preferable over the macro.

---
Changes in v2 -

- Corrected commit log spelling
- Made the subject line unique from previous commit

---
 drivers/staging/media/davinci_vpfe/dm365_ipipe.h   | 5 ++++-
 drivers/staging/media/davinci_vpfe/dm365_resizer.c | 4 ++--
 2 files changed, 6 insertions(+), 3 deletions(-)
drivers/staging/media/davinci_vpfe/dm365_ipipe.h +4 -1
index 174334b53f96..32dce3c95304 100644
@@ -27,7 +27,10 @@
 #include "davinci_vpfe_user.h"
 #include "vpfe_video.h"
 
-#define CEIL(a, b)	(((a) + (b-1)) / (b))
+inline unsigned int ceil(unsigned int a, unsigned int b)
+{
+	return ((a + (b - 1)) / b);
+}
 
 enum ipipe_noise_filter {
 	IPIPE_D2F_1ST = 0,
drivers/staging/media/davinci_vpfe/dm365_resizer.c +2 -2
index 9d726298b406..395c66520932 100644
@@ -386,7 +386,7 @@ resizer_calculate_down_scale_f_div_param(struct device *dev,
 	}
 	o = 10 + (two_power << 2);
 	if (((input_width << 7) / rsz) % 2)
-		o += (((CEIL(rsz, 1024)) << 1) << n);
+		o += ((ceil(rsz, 1024) << 1) << n);
 	h2 = output_width - h1;
 	/* phi */
 	val = (h1 * rsz) - (((upper_h1 - (o - 10)) / two_power) << 8);
@@ -630,7 +630,7 @@ resizer_calculate_normal_f_div_param(struct device *dev, int input_width,
 		val /= rsz << 1;
 		val <<= 1;
 		val += 2;
-		o += ((CEIL(rsz, 1024)) << 1);
+		o += (ceil(rsz, 1024) << 1);
 		h1 = val;
 	}
 	h2 = output_width - h1;
Signature · 1 line
2.17.1
maintainer
#1 lore raw
Quoted 21 lines · Madhumitha Prabakaran

Convert macro into an inline function in order to maintain Linux kernel coding style based on which the inline function is preferable over the macro.

---
Changes in v2 -

- Corrected commit log spelling
- Made the subject line unique from previous commit

---
 drivers/staging/media/davinci_vpfe/dm365_ipipe.h   | 5 ++++-
 drivers/staging/media/davinci_vpfe/dm365_resizer.c | 4 ++--
 2 files changed, 6 insertions(+), 3 deletions(-)
drivers/staging/media/davinci_vpfe/dm365_ipipe.h +0 -0
index 174334b53f96..32dce3c95304 100644

drivers/staging/media/davinci_vpfe/dm365_ipipe.h line 33

Quoted 8 lines
drivers/staging/media/davinci_vpfe/dm365_ipipe.h +4 -1
@@ -27,7 +27,10 @@
 #include "davinci_vpfe_user.h"
 #include "vpfe_video.h"
 
-#define CEIL(a, b)	(((a) + (b-1)) / (b))
+inline unsigned int ceil(unsigned int a, unsigned int b)
+{
+	return ((a + (b - 1)) / b);
+}

Please just convert the caller to use the in-kernel function for this instead of having a second one in just this driver.

thanks,

greg k-h

#2 lore raw
Quoted 25 lines · Greg KH
Quoted 24 lines · Madhumitha Prabakaran

Convert macro into an inline function in order to maintain Linux kernel coding style based on which the inline function is preferable over the macro.

---
Changes in v2 -

- Corrected commit log spelling
- Made the subject line unique from previous commit

---
 drivers/staging/media/davinci_vpfe/dm365_ipipe.h   | 5 ++++-
 drivers/staging/media/davinci_vpfe/dm365_resizer.c | 4 ++--
 2 files changed, 6 insertions(+), 3 deletions(-)
drivers/staging/media/davinci_vpfe/dm365_ipipe.h +0 -0
index 174334b53f96..32dce3c95304 100644
@@ -27,7 +27,10 @@
 #include "davinci_vpfe_user.h"
 #include "vpfe_video.h"
 
Quoted 8 lines

drivers/staging/media/davinci_vpfe/dm365_ipipe.h line 33

Quoted 5 lines
drivers/staging/media/davinci_vpfe/dm365_ipipe.h +4 -1
-#define CEIL(a, b)	(((a) + (b-1)) / (b))
+inline unsigned int ceil(unsigned int a, unsigned int b)
+{
+	return ((a + (b - 1)) / b);
+}

Please just convert the caller to use the in-kernel function for this instead of having a second one in just this driver.

I'm not able to find in-kernel function for ceil. Though there is ceil function in math.h, which has return type of double, and i'm sure that kernel cann't accept floating type. how can i resolve this issue?

thanks

Quoted 4 lines

thanks,

greg k-h

maintainer
#3 lore raw
Quoted 35 lines · Madhumthia Prabakaran
Quoted 25 lines · Greg KH
Quoted 24 lines · Madhumitha Prabakaran

Convert macro into an inline function in order to maintain Linux kernel coding style based on which the inline function is preferable over the macro.

---
Changes in v2 -

- Corrected commit log spelling
- Made the subject line unique from previous commit

---
 drivers/staging/media/davinci_vpfe/dm365_ipipe.h   | 5 ++++-
 drivers/staging/media/davinci_vpfe/dm365_resizer.c | 4 ++--
 2 files changed, 6 insertions(+), 3 deletions(-)
drivers/staging/media/davinci_vpfe/dm365_ipipe.h +0 -0
index 174334b53f96..32dce3c95304 100644
@@ -27,7 +27,10 @@
 #include "davinci_vpfe_user.h"
 #include "vpfe_video.h"
 
Quoted 8 lines

drivers/staging/media/davinci_vpfe/dm365_ipipe.h line 33

Quoted 5 lines
drivers/staging/media/davinci_vpfe/dm365_ipipe.h +4 -1
-#define CEIL(a, b)	(((a) + (b-1)) / (b))
+inline unsigned int ceil(unsigned int a, unsigned int b)
+{
+	return ((a + (b - 1)) / b);
+}

Please just convert the caller to use the in-kernel function for this instead of having a second one in just this driver.

Quoted 3 lines

I'm not able to find in-kernel function for ceil. Though there is ceil function in math.h, which has return type of double, and i'm sure that kernel cann't accept floating type. how can i resolve this issue?

The kernel does not have a math.h file, I do not think you are looking in the kernel include directory.

Look at DIV_ROUND_UP(), that's what you want, right?

thanks,

greg k-h

#4 lore raw
Quoted 36 lines · Greg KH
Quoted 35 lines · Madhumthia Prabakaran
Quoted 33 lines · Greg KH
Quoted 21 lines · Madhumitha Prabakaran

Convert macro into an inline function in order to maintain Linux kernel coding style based on which the inline function is preferable over the macro.

---
Changes in v2 -

- Corrected commit log spelling
- Made the subject line unique from previous commit

---
 drivers/staging/media/davinci_vpfe/dm365_ipipe.h   | 5 ++++-
 drivers/staging/media/davinci_vpfe/dm365_resizer.c | 4 ++--
 2 files changed, 6 insertions(+), 3 deletions(-)
drivers/staging/media/davinci_vpfe/dm365_ipipe.h +0 -0
index 174334b53f96..32dce3c95304 100644

drivers/staging/media/davinci_vpfe/dm365_ipipe.h line 33

Quoted 8 lines
drivers/staging/media/davinci_vpfe/dm365_ipipe.h +4 -1
@@ -27,7 +27,10 @@
 #include "davinci_vpfe_user.h"
 #include "vpfe_video.h"
 
-#define CEIL(a, b)	(((a) + (b-1)) / (b))
+inline unsigned int ceil(unsigned int a, unsigned int b)
+{
+	return ((a + (b - 1)) / b);
+}

Please just convert the caller to use the in-kernel function for this instead of having a second one in just this driver.

Quoted 8 lines
Quoted 3 lines

I'm not able to find in-kernel function for ceil. Though there is ceil function in math.h, which has return type of double, and i'm sure that kernel cann't accept floating type. how can i resolve this issue?

The kernel does not have a math.h file, I do not think you are looking in the kernel include directory.

Look at DIV_ROUND_UP(), that's what you want, right?

Thanks

Quoted 4 lines

thanks,

greg k-h