From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8143AC76188 for ; Fri, 19 Jul 2019 07:19:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5D003218A5 for ; Fri, 19 Jul 2019 07:19:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727116AbfGSHTS (ORCPT ); Fri, 19 Jul 2019 03:19:18 -0400 Received: from mga12.intel.com ([192.55.52.136]:9129 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726135AbfGSHTS (ORCPT ); Fri, 19 Jul 2019 03:19:18 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Jul 2019 00:19:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,281,1559545200"; d="scan'208";a="343617583" Received: from crojewsk-mobl1.ger.corp.intel.com (HELO [10.251.81.172]) ([10.251.81.172]) by orsmga005.jf.intel.com with ESMTP; 19 Jul 2019 00:19:12 -0700 Subject: Re: [PATCH v5 2/6] ASoC: sgtl5000: Improve VAG power and mute control To: Oleksandr Suvorov Cc: Fabio Estevam , "linux-kernel@vger.kernel.org" , Igor Opaniuk , Marcel Ziswiler , "alsa-devel@alsa-project.org" , "stable@vger.kernel.org" , Jaroslav Kysela , Sasha Levin , Mark Brown , Takashi Iwai , Liam Girdwood References: <20190718090240.18432-1-oleksandr.suvorov@toradex.com> <20190718090240.18432-3-oleksandr.suvorov@toradex.com> <9c9ee47c-48bd-7109-9870-8f73be1f1cfa@intel.com> From: Cezary Rojewski Message-ID: <3c153dcc-e656-2959-6281-15cc895660e0@intel.com> Date: Fri, 19 Jul 2019 09:19:10 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2019-07-19 09:09, Oleksandr Suvorov wrote: > On Thu, 18 Jul 2019 at 21:49, Cezary Rojewski wrote: >> >> On 2019-07-18 20:42, Cezary Rojewski wrote: >>> On 2019-07-18 11:02, Oleksandr Suvorov wrote: >>>> +enum { >>>> + HP_POWER_EVENT, >>>> + DAC_POWER_EVENT, >>>> + ADC_POWER_EVENT, >>>> + LAST_POWER_EVENT >>>> +}; >>>> + >>>> +static u16 mute_mask[] = { >>>> + SGTL5000_HP_MUTE, >>>> + SGTL5000_OUTPUTS_MUTE, >>>> + SGTL5000_OUTPUTS_MUTE >>>> +}; >>> >>> If mute_mask[] is only used within common handler, you may consider >>> declaring const array within said handler instead (did not check that >>> myself). >>> Otherwise, simple comment for the second _OUTPUTS_MUTE should suffice - >>> its not self explanatory why you doubled that mask. > > Ok, I'll add a comment to explain doubled mask. > >>> >>>> + >>>> /* sgtl5000 private structure in codec */ >>>> struct sgtl5000_priv { >>>> int sysclk; /* sysclk rate */ >>>> @@ -137,8 +157,109 @@ struct sgtl5000_priv { >>>> u8 micbias_voltage; >>>> u8 lrclk_strength; >>>> u8 sclk_strength; >>>> + u16 mute_state[LAST_POWER_EVENT]; >>>> }; >>> >>> When I spoke of LAST enum constant, I did not really had this specific >>> usage in mind. >>> >>> From design perspective, _LAST_ does not exist and should never be >>> referred to as "the next option" i.e.: new enum constant. > > By its nature, LAST_POWER_EVENT is actually a size of the array, but I > couldn't come up with a better name. > >>> That is way preferred usage is: >>> u16 mute_state[ADC_POWER_EVENT+1; >>> -or- >>> u16 mute_state[LAST_POWER_EVENT+1]; >>> >>> Maybe I'm just being radical here :) > > Maybe :) I don't like first variant (ADC_POWER_EVENT+1): somewhen in > future, someone can add a new event to this enum and we've got a > possible situation with "out of array indexing". > >>> >>> Czarek >> >> Forgive me for double posting. Comment above is targeted towards: >> >> >> +enum { >> >> + HP_POWER_EVENT, >> >> + DAC_POWER_EVENT, >> >> + ADC_POWER_EVENT, >> >> + LAST_POWER_EVENT >> >> +}; >> >> as LAST_POWER_EVENT is not assigned explicitly to ADC_POWER_EVENT and >> thus generates implicit "new option" of value 3. > > So will you be happy with the following variant? > ... > ADC_POWER_EVENT, > LAST_POWER_EVENT = ADC_POWER_EVENT, > ... > u16 mute_state[LAST_POWER_EVENT+1]; > ... > It's not about being happy - I'm a happy man in general ;p As stated already, declaring _LAST_ as the "new option" is misleading and not advised. And yeah, [_LAST_ + 1] is usually the one you should go with. Czarek