Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753029AbeABATN (ORCPT + 1 other); Mon, 1 Jan 2018 19:19:13 -0500 Received: from mail-pg0-f65.google.com ([74.125.83.65]:35121 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752857AbeABATL (ORCPT ); Mon, 1 Jan 2018 19:19:11 -0500 X-Google-Smtp-Source: ACJfBouOIzxWbnTyrZYAE42okD899VHD2QvbFmhFrR0nbZWaHQ911F8FiCUY7sdkwwRzqDITAHBwWw== Date: Mon, 1 Jan 2018 16:19:07 -0800 From: Bjorn Andersson To: srinivas.kandagatla@linaro.org Cc: Andy Gross , Mark Brown , linux-arm-msm@vger.kernel.org, alsa-devel@alsa-project.org, Mark Rutland , devicetree@vger.kernel.org, Banajit Goswami , linux-kernel@vger.kernel.org, Patrick Lai , Takashi Iwai , sboyd@codeaurora.org, Liam Girdwood , Jaroslav Kysela , David Brown , Rob Herring , linux-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: Re: [RESEND PATCH v2 03/15] ASoC: qcom: qdsp6: Add common qdsp6 helper functions Message-ID: <20180102001907.GL478@tuxbook> References: <20171214173402.19074-1-srinivas.kandagatla@linaro.org> <20171214173402.19074-4-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20171214173402.19074-4-srinivas.kandagatla@linaro.org> User-Agent: Mutt/1.9.1 (2017-09-22) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: On Thu 14 Dec 09:33 PST 2017, srinivas.kandagatla@linaro.org wrote: > +static inline int q6dsp_map_channels(u8 *ch_map, int ch) > +{ > + memset(ch_map, 0, PCM_FORMAT_MAX_NUM_CHANNEL); This implies that ch_map is always an array of PCM_FORMAT_MAX_NUM_CHANNEL elements. As such it would be better to express this in the prototype; i.e u8 ch_map[PCM_FORMAT_MAX_NUM_CHANNEL] > + > + if (ch == 1) { This is a switch statement. > + ch_map[0] = PCM_CHANNEL_FC; > + } else if (ch == 2) { [..] > +struct adsp_err_code { > + int lnx_err_code; Indentation, and these could be given more succinct names. > + char *adsp_err_str; > +}; > + > +static struct adsp_err_code adsp_err_code_info[ADSP_ERR_MAX+1] = { > + { 0, ADSP_EOK_STR}, > + { -ENOTRECOVERABLE, ADSP_EFAILED_STR}, > + { -EINVAL, ADSP_EBADPARAM_STR}, > + { -ENOSYS, ADSP_EUNSUPPORTED_STR}, > + { -ENOPROTOOPT, ADSP_EVERSION_STR}, > + { -ENOTRECOVERABLE, ADSP_EUNEXPECTED_STR}, > + { -ENOTRECOVERABLE, ADSP_EPANIC_STR}, > + { -ENOSPC, ADSP_ENORESOURCE_STR}, > + { -EBADR, ADSP_EHANDLE_STR}, > + { -EALREADY, ADSP_EALREADY_STR}, > + { -EPERM, ADSP_ENOTREADY_STR}, > + { -EINPROGRESS, ADSP_EPENDING_STR}, > + { -EBUSY, ADSP_EBUSY_STR}, > + { -ECANCELED, ADSP_EABORTED_STR}, > + { -EAGAIN, ADSP_EPREEMPTED_STR}, > + { -EAGAIN, ADSP_ECONTINUE_STR}, > + { -EAGAIN, ADSP_EIMMEDIATE_STR}, > + { -EAGAIN, ADSP_ENOTIMPL_STR}, > + { -ENODATA, ADSP_ENEEDMORE_STR}, > + { -EADV, ADSP_ERR_MAX_STR}, This, element 0x13, is not listed among the defined errors. Is this a placeholder? How about making this even more descriptive by using the format [ADSP_EBADPARAM] = { -EINVAL, ADSP_EBADPARAM_STR }, That way the mapping table is self-describing. And you can use ARRAY_SIZE() instead of specifying the fixed size of ADSP_ERR_MAX + 1... > + { -ENOMEM, ADSP_ENOMEMORY_STR}, > + { -ENODEV, ADSP_ENOTEXIST_STR}, > + { -EADV, ADSP_ERR_MAX_STR}, "Advertise error"? > +}; > + > +static inline int adsp_err_get_lnx_err_code(u32 adsp_error) Can this be made internal to some c-file? So that any third party deals only with linux error codes? How about renaming this q6dsp_errno()? > +{ > + if (adsp_error > ADSP_ERR_MAX) > + return adsp_err_code_info[ADSP_ERR_MAX].lnx_err_code; > + else > + return adsp_err_code_info[adsp_error].lnx_err_code; I think this would look better if you assign a local variable and have a single return. And just hard code the "invalid error code" errno, rather than looking up ADSP_ERR_MAX in the list. > +} > + > +static inline char *adsp_err_get_err_str(u32 adsp_error) q6dsp_strerror(), to match strerror(3)? > +{ > + if (adsp_error > ADSP_ERR_MAX) > + return adsp_err_code_info[ADSP_ERR_MAX].adsp_err_str; > + else > + return adsp_err_code_info[adsp_error].adsp_err_str; And I do think that, as with strerror, this should return a human readable error, not the stringified define. > +} I'm puzzled to why these helper functions lives in a header file, at least some aspects of this would better be hidden... Regards, Bjorn