Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754571AbcK1DIK (ORCPT ); Sun, 27 Nov 2016 22:08:10 -0500 Received: from server.coly.li ([162.144.45.48]:33658 "EHLO server.coly.li" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754425AbcK1DHF (ORCPT ); Sun, 27 Nov 2016 22:07:05 -0500 Subject: Re: [PATCH v2] Avoid nested function definition To: Peter Foley , linux-kernel@vger.kernel.org, shli@kernel.org, linux-bcache@vger.kernel.org, linux-raid@vger.kernel.org, kent.overstreet@gmail.com References: <20161128025004.18782-1-pefoley2@pefoley.com> From: Coly Li Message-ID: <4e5b3f6f-695b-5bfe-3f62-c50fe9e984c3@coly.li> Date: Mon, 28 Nov 2016 11:06:53 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:45.0) Gecko/20100101 Thunderbird/45.5.0 MIME-Version: 1.0 In-Reply-To: <20161128025004.18782-1-pefoley2@pefoley.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - server.coly.li X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - coly.li X-Get-Message-Sender-Via: server.coly.li: authenticated_id: i@coly.li X-Authenticated-Sender: server.coly.li: i@coly.li X-Source: X-Source-Args: X-Source-Dir: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1866 Lines: 59 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 > --- > 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 -- Coly Li