Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753561AbbGOUb2 (ORCPT ); Wed, 15 Jul 2015 16:31:28 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:55549 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752995AbbGOUb1 (ORCPT ); Wed, 15 Jul 2015 16:31:27 -0400 Date: Wed, 15 Jul 2015 13:31:26 -0700 From: Andrew Morton To: Rusty Russell Cc: Minfei Huang , rob.jones@codethink.co.uk, amhyung@kernel.org, linux-kernel@vger.kernel.org, Minfei Huang Subject: Re: [PATCH 1/2] Define find_symbol_in_section_t as function type to simplify the code Message-Id: <20150715133126.c13ff1e75bf36eb0a85dcb3f@linux-foundation.org> In-Reply-To: <87twt676fz.fsf@rustcorp.com.au> References: <1436857153-18874-1-git-send-email-mhuang@redhat.com> <1436857153-18874-2-git-send-email-mhuang@redhat.com> <87twt676fz.fsf@rustcorp.com.au> X-Mailer: Sylpheed 3.4.1 (GTK+ 2.24.23; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1843 Lines: 46 On Wed, 15 Jul 2015 07:22:32 +0930 Rusty Russell wrote: > Minfei Huang writes: > > From: Minfei Huang > > > > It is not elegance, if we use function directly as the argument, like > > following: > > > > bool each_symbol_section(bool (*fn)(const struct symsearch *arr, > > struct module *owner, > > void *data), void *data); > > > > Here introduce a type defined function find_symbol_in_section_t. Now > > we can use these type defined function directly, if we want to pass > > the function as the argument. > > > > bool each_symbol_section(find_symbol_in_section_t fn, void *data); > > I disagree. > > It's shorter, but it's less clear. typedefs on functions are not very > useful: > 1) They require readers to look in two places to see how to use the > function (ie each_symbol_section). > 2) They can't use the typedef to declare their function, since that > doesn't work in C. > > If the function were being used many times, it makes sense. But > it's only used twice, once static inside module.c. > Using a foo_t typedef for a function callback is a common pattern. It's (almost) the only approved use of typedefs. The usage is widespread enough that when one sees a foo_t type, one says "ahah, that's a function pointer". Sorry, but I don't think "Rusty doesn't like it" is a good reason for the module code to be different. All of us dislike some aspects of kernel coding practices, but we go along because consistency is more important. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/