From: Takashi Iwai <tiwai@suse.de> To: Mark Brown <broonie@kernel.org> Cc: Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>, Shuah Khan <shuah@kernel.org>, alsa-devel@alsa-project.org, linux-kselftest@vger.kernel.org Subject: Re: [PATCH] selftests: alsa: Start validating control names Date: Thu, 21 Apr 2022 09:50:33 +0200 [thread overview] Message-ID: <s5h8rryx4c6.wl-tiwai@suse.de> (raw) In-Reply-To: <20220420203320.3035329-1-broonie@kernel.org> On Wed, 20 Apr 2022 22:33:20 +0200, Mark Brown wrote: > > +bool strend(const char *haystack, const char *needle) Missing static? > +{ > + size_t haystack_len = strlen(haystack); > + size_t needle_len = strlen(needle); > + > + if (needle_len > haystack_len) > + return false; > + return strcmp(haystack + haystack_len - needle_len, needle) == 0; > +} > + > +static void test_ctl_name(struct ctl_data *ctl) > +{ > + bool name_ok = true; > + bool check; > + > + /* Only boolean controls should end in Switch */ > + if (strend(ctl->name, "Switch")) { This should be with " Switch" so that it won't check a concatenated word. > + if (snd_ctl_elem_info_get_type(ctl->info) != SND_CTL_ELEM_TYPE_BOOLEAN) { > + ksft_print_msg("%d.%d %s ends in Switch but is not boolean\n", > + ctl->card->card, ctl->elem, ctl->name); > + name_ok = false; > + } > + } > + > + /* Writeable boolean controls should end in Switch */ > + if (snd_ctl_elem_info_get_type(ctl->info) == SND_CTL_ELEM_TYPE_BOOLEAN && > + snd_ctl_elem_info_is_writable(ctl->info)) { > + if (!strend(ctl->name, "Switch")) { > + ksft_print_msg("%d.%d %s is a writeable boolean but not a Switch\n", > + ctl->card->card, ctl->elem, ctl->name); > + name_ok = false; I'm afraid that this would hit too many when applying to the existing code; although the control name should be indeed with Switch suffix, we tend to allow without suffix for casual non-standard elements. But having the check would help for avoiding such a mistake for the future code, so it's fine to add this strict check, IMO. thanks, Takashi
WARNING: multiple messages have this Message-ID (diff)
From: Takashi Iwai <tiwai@suse.de> To: Mark Brown <broonie@kernel.org> Cc: alsa-devel@alsa-project.org, Shuah Khan <shuah@kernel.org>, Takashi Iwai <tiwai@suse.com>, linux-kselftest@vger.kernel.org Subject: Re: [PATCH] selftests: alsa: Start validating control names Date: Thu, 21 Apr 2022 09:50:33 +0200 [thread overview] Message-ID: <s5h8rryx4c6.wl-tiwai@suse.de> (raw) In-Reply-To: <20220420203320.3035329-1-broonie@kernel.org> On Wed, 20 Apr 2022 22:33:20 +0200, Mark Brown wrote: > > +bool strend(const char *haystack, const char *needle) Missing static? > +{ > + size_t haystack_len = strlen(haystack); > + size_t needle_len = strlen(needle); > + > + if (needle_len > haystack_len) > + return false; > + return strcmp(haystack + haystack_len - needle_len, needle) == 0; > +} > + > +static void test_ctl_name(struct ctl_data *ctl) > +{ > + bool name_ok = true; > + bool check; > + > + /* Only boolean controls should end in Switch */ > + if (strend(ctl->name, "Switch")) { This should be with " Switch" so that it won't check a concatenated word. > + if (snd_ctl_elem_info_get_type(ctl->info) != SND_CTL_ELEM_TYPE_BOOLEAN) { > + ksft_print_msg("%d.%d %s ends in Switch but is not boolean\n", > + ctl->card->card, ctl->elem, ctl->name); > + name_ok = false; > + } > + } > + > + /* Writeable boolean controls should end in Switch */ > + if (snd_ctl_elem_info_get_type(ctl->info) == SND_CTL_ELEM_TYPE_BOOLEAN && > + snd_ctl_elem_info_is_writable(ctl->info)) { > + if (!strend(ctl->name, "Switch")) { > + ksft_print_msg("%d.%d %s is a writeable boolean but not a Switch\n", > + ctl->card->card, ctl->elem, ctl->name); > + name_ok = false; I'm afraid that this would hit too many when applying to the existing code; although the control name should be indeed with Switch suffix, we tend to allow without suffix for casual non-standard elements. But having the check would help for avoiding such a mistake for the future code, so it's fine to add this strict check, IMO. thanks, Takashi
next prev parent reply other threads:[~2022-04-21 7:50 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-04-20 20:33 [PATCH] selftests: alsa: Start validating control names Mark Brown 2022-04-20 20:33 ` Mark Brown 2022-04-21 7:50 ` Takashi Iwai [this message] 2022-04-21 7:50 ` Takashi Iwai 2022-04-21 12:39 ` Mark Brown 2022-04-21 12:39 ` Mark Brown
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=s5h8rryx4c6.wl-tiwai@suse.de \ --to=tiwai@suse.de \ --cc=alsa-devel@alsa-project.org \ --cc=broonie@kernel.org \ --cc=linux-kselftest@vger.kernel.org \ --cc=perex@perex.cz \ --cc=shuah@kernel.org \ --cc=tiwai@suse.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.