Linux RAID subsystem development
 help / color / mirror / Atom feed
* [PATCH] Avoid nested function definition
@ 2016-11-26 22:24 Peter Foley
  2016-11-27  4:06 ` Coly Li
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Foley @ 2016-11-26 22:24 UTC (permalink / raw)
  To: linux-kernel, kent.overstreet, shli, linux-bcache, linux-raid; +Cc: Peter Foley

Fixes below error with clang:
../drivers/md/bcache/sysfs.c:759:3: error: function definition is not allowed here
                {       return *((uint16_t *) r) - *((uint16_t *) l); }
                ^
../drivers/md/bcache/sysfs.c:789:32: error: use of undeclared identifier 'cmp'
                sort(p, n, sizeof(uint16_t), cmp, NULL);
                                             ^
2 errors generated.

Signed-off-by: Peter Foley <pefoley2@pefoley.com>
---
 drivers/md/bcache/sysfs.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/md/bcache/sysfs.c b/drivers/md/bcache/sysfs.c
index b3ff57d61dde..22ac9e6676a0 100644
--- a/drivers/md/bcache/sysfs.c
+++ b/drivers/md/bcache/sysfs.c
@@ -731,6 +731,11 @@ static struct attribute *bch_cache_set_internal_files[] = {
 };
 KTYPE(bch_cache_set_internal);
 
+static int cmp(const void *l, const void *r)
+{
+	return *((uint16_t *)r) - *((uint16_t *)l);
+}
+
 SHOW(__bch_cache)
 {
 	struct cache *ca = container_of(kobj, struct cache, kobj);
@@ -755,9 +760,6 @@ SHOW(__bch_cache)
 					       CACHE_REPLACEMENT(&ca->sb));
 
 	if (attr == &sysfs_priority_stats) {
-		int cmp(const void *l, const void *r)
-		{	return *((uint16_t *) r) - *((uint16_t *) l); }
-
 		struct bucket *b;
 		size_t n = ca->sb.nbuckets, i;
 		size_t unused = 0, available = 0, dirty = 0, meta = 0;
-- 
2.11.0.rc2

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

* Re: [PATCH] Avoid nested function definition
  2016-11-26 22:24 [PATCH] Avoid nested function definition Peter Foley
@ 2016-11-27  4:06 ` Coly Li
  2016-11-28  2:50   ` [PATCH v2] " Peter Foley
  0 siblings, 1 reply; 4+ messages in thread
From: Coly Li @ 2016-11-27  4:06 UTC (permalink / raw)
  To: Peter Foley, shli, linux-bcache, linux-raid; +Cc: linux-kernel, kent.overstreet

On 2016/11/27 上午6:24, Peter Foley wrote:
> Fixes below error with clang:
> ../drivers/md/bcache/sysfs.c:759:3: error: function definition is not allowed here
>                 {       return *((uint16_t *) r) - *((uint16_t *) l); }
>                 ^
> ../drivers/md/bcache/sysfs.c:789:32: error: use of undeclared identifier 'cmp'
>                 sort(p, n, sizeof(uint16_t), cmp, NULL);
>                                              ^
> 2 errors generated.
> 
> Signed-off-by: Peter Foley <pefoley2@pefoley.com>
> ---
>  drivers/md/bcache/sysfs.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/md/bcache/sysfs.c b/drivers/md/bcache/sysfs.c
> index b3ff57d61dde..22ac9e6676a0 100644
> --- a/drivers/md/bcache/sysfs.c
> +++ b/drivers/md/bcache/sysfs.c
> @@ -731,6 +731,11 @@ static struct attribute *bch_cache_set_internal_files[] = {
>  };
>  KTYPE(bch_cache_set_internal);
>  
> +static int cmp(const void *l, const void *r)
> +{
> +	return *((uint16_t *)r) - *((uint16_t *)l);
> +}
> +
>  SHOW(__bch_cache)
>  {
>  	struct cache *ca = container_of(kobj, struct cache, kobj);
> @@ -755,9 +760,6 @@ SHOW(__bch_cache)
>  					       CACHE_REPLACEMENT(&ca->sb));
>  
>  	if (attr == &sysfs_priority_stats) {
> -		int cmp(const void *l, const void *r)
> -		{	return *((uint16_t *) r) - *((uint16_t *) l); }
> -
>  		struct bucket *b;
>  		size_t n = ca->sb.nbuckets, i;
>  		size_t unused = 0, available = 0, dirty = 0, meta = 0;
> 

 I agree with this fix. Anyway, Can we use a more unique name like
__bch_cache_cmp() ?

Thanks.

-- 
Coly Li

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

* [PATCH v2] Avoid nested function definition
  2016-11-27  4:06 ` Coly Li
@ 2016-11-28  2:50   ` Peter Foley
  2016-11-28  3:06     ` Coly Li
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Foley @ 2016-11-28  2:50 UTC (permalink / raw)
  To: linux-kernel, shli, linux-bcache, linux-raid, i, kent.overstreet
  Cc: Peter Foley

Fixes below error with clang:
../drivers/md/bcache/sysfs.c:759:3: error: function definition is not allowed here
                {       return *((uint16_t *) r) - *((uint16_t *) l); }
                ^
../drivers/md/bcache/sysfs.c:789:32: error: use of undeclared identifier 'cmp'
                sort(p, n, sizeof(uint16_t), cmp, NULL);
                                             ^
2 errors generated.

v2:
rename function to __bch_cache_cmp

Signed-off-by: Peter Foley <pefoley2@pefoley.com>
---
 drivers/md/bcache/sysfs.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/md/bcache/sysfs.c b/drivers/md/bcache/sysfs.c
index b3ff57d61dde..8f12089a69e7 100644
--- a/drivers/md/bcache/sysfs.c
+++ b/drivers/md/bcache/sysfs.c
@@ -731,6 +731,11 @@ static struct attribute *bch_cache_set_internal_files[] = {
 };
 KTYPE(bch_cache_set_internal);
 
+static int __bch_cache_cmp(const void *l, const void *r)
+{
+	return *((uint16_t *)r) - *((uint16_t *)l);
+}
+
 SHOW(__bch_cache)
 {
 	struct cache *ca = container_of(kobj, struct cache, kobj);
@@ -755,9 +760,6 @@ SHOW(__bch_cache)
 					       CACHE_REPLACEMENT(&ca->sb));
 
 	if (attr == &sysfs_priority_stats) {
-		int cmp(const void *l, const void *r)
-		{	return *((uint16_t *) r) - *((uint16_t *) l); }
-
 		struct bucket *b;
 		size_t n = ca->sb.nbuckets, i;
 		size_t unused = 0, available = 0, dirty = 0, meta = 0;
@@ -786,7 +788,7 @@ SHOW(__bch_cache)
 			p[i] = ca->buckets[i].prio;
 		mutex_unlock(&ca->set->bucket_lock);
 
-		sort(p, n, sizeof(uint16_t), cmp, NULL);
+		sort(p, n, sizeof(uint16_t), __bch_cache_cmp, NULL);
 
 		while (n &&
 		       !cached[n - 1])
-- 
2.11.0.rc2


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

* Re: [PATCH v2] Avoid nested function definition
  2016-11-28  2:50   ` [PATCH v2] " Peter Foley
@ 2016-11-28  3:06     ` Coly Li
  0 siblings, 0 replies; 4+ messages in thread
From: Coly Li @ 2016-11-28  3:06 UTC (permalink / raw)
  To: Peter Foley, linux-kernel, shli, linux-bcache, linux-raid,
	kent.overstreet

On 2016/11/28 上午10:50, Peter Foley wrote:
> Fixes below error with clang:
> ../drivers/md/bcache/sysfs.c:759:3: error: function definition is not allowed here
>                 {       return *((uint16_t *) r) - *((uint16_t *) l); }
>                 ^
> ../drivers/md/bcache/sysfs.c:789:32: error: use of undeclared identifier 'cmp'
>                 sort(p, n, sizeof(uint16_t), cmp, NULL);
>                                              ^
> 2 errors generated.
> 
> v2:
> rename function to __bch_cache_cmp
> 
> Signed-off-by: Peter Foley <pefoley2@pefoley.com>
> ---
>  drivers/md/bcache/sysfs.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/md/bcache/sysfs.c b/drivers/md/bcache/sysfs.c
> index b3ff57d61dde..8f12089a69e7 100644
> --- a/drivers/md/bcache/sysfs.c
> +++ b/drivers/md/bcache/sysfs.c
> @@ -731,6 +731,11 @@ static struct attribute *bch_cache_set_internal_files[] = {
>  };
>  KTYPE(bch_cache_set_internal);
>  
> +static int __bch_cache_cmp(const void *l, const void *r)
> +{
> +	return *((uint16_t *)r) - *((uint16_t *)l);
> +}
> +
>  SHOW(__bch_cache)
>  {
>  	struct cache *ca = container_of(kobj, struct cache, kobj);
> @@ -755,9 +760,6 @@ SHOW(__bch_cache)
>  					       CACHE_REPLACEMENT(&ca->sb));
>  
>  	if (attr == &sysfs_priority_stats) {
> -		int cmp(const void *l, const void *r)
> -		{	return *((uint16_t *) r) - *((uint16_t *) l); }
> -
>  		struct bucket *b;
>  		size_t n = ca->sb.nbuckets, i;
>  		size_t unused = 0, available = 0, dirty = 0, meta = 0;
> @@ -786,7 +788,7 @@ SHOW(__bch_cache)
>  			p[i] = ca->buckets[i].prio;
>  		mutex_unlock(&ca->set->bucket_lock);
>  
> -		sort(p, n, sizeof(uint16_t), cmp, NULL);
> +		sort(p, n, sizeof(uint16_t), __bch_cache_cmp, NULL);
>  
>  		while (n &&
>  		       !cached[n - 1])
> 

Acked-by: Coly Li <colyli@suse.de>

-- 
Coly Li

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

end of thread, other threads:[~2016-11-28  3:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-26 22:24 [PATCH] Avoid nested function definition Peter Foley
2016-11-27  4:06 ` Coly Li
2016-11-28  2:50   ` [PATCH v2] " Peter Foley
2016-11-28  3:06     ` Coly Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox