Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933925AbbENUfl (ORCPT ); Thu, 14 May 2015 16:35:41 -0400 Received: from smtp208.alice.it ([82.57.200.104]:21016 "EHLO smtp208.alice.it" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933019AbbENUfk (ORCPT ); Thu, 14 May 2015 16:35:40 -0400 X-Greylist: delayed 301 seconds by postgrey-1.27 at vger.kernel.org; Thu, 14 May 2015 16:35:40 EDT Date: Thu, 14 May 2015 22:32:06 +0200 From: Giuliano Pochini To: Denys Vlasenko Cc: Takashi Iwai , Jaroslav Kysela , LKML Subject: Re: Object code duplication in sound/pci/echoaudio/ Message-ID: <20150514223206.04d6b79e@wc1> In-Reply-To: <55510DE0.3080909@redhat.com> References: <55510DE0.3080909@redhat.com> X-Mailer: Claws Mail 3.8.0 (GTK+ 2.24.10; x86_64-unknown-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: 1848 Lines: 51 On Mon, 11 May 2015 22:15:28 +0200 Denys Vlasenko wrote: > There are fourteen files in sound/pci/echoaudio/, namely: > > darla20.c darla24.c echo3g.c gina20.c gina24.c indigo.c > indigodj.c indigodjx.c indigoio.c indigoiox.c layla20.c > layla24.c mia.c mona.c > > Which use the following method of "code reuse": > > #include "echoaudio_dsp.c" > #include "echoaudio_gml.c" > #include "echoaudio.c" > > echoaudio.c is not a header file, it contains a bunch of > static functions, some of a considerable size. > This makes those functions to be duplicated many times over. Not really. It is quite unlikely that there are two different Echoaudio cards installed. > For instance, there are fourteen instances of init_engine(), > each 1117 bytes long. Fourteen instances of pcm_open(), each 556 bytes > long. > > 11 get_firmware > 10 free_firmware > 13 audiopipe_free > 14 init_hw > 14 hw_rule_capture_format_by_channels > 14 hw_rule_capture_channels_by_format > 14 hw_rule_playback_format_by_channels > 14 hw_rule_playback_channels_by_format > > and so on. > > In my humble opinion, this is not a good coding practice. > You should not duplicate functions like this. > Where possible, you need to reuse a single instance of a function. One option is to make a single driver which supports all the cards. There is not any duplicated code, but there is a lot of unused code. The other way (the one I choosed) is to build many specialized drivers. There is duplicated code overall, but given a single installed card there is neither duplicated not unused code. -- Giuliano. -- 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/