Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AD20DC433F5 for ; Thu, 21 Apr 2022 07:50:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1386288AbiDUHxe (ORCPT ); Thu, 21 Apr 2022 03:53:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386310AbiDUHxc (ORCPT ); Thu, 21 Apr 2022 03:53:32 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1D2EE0F1 for ; Thu, 21 Apr 2022 00:50:34 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 7FC721F752; Thu, 21 Apr 2022 07:50:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1650527433; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=CA8kHCu+RuJ2Qz5MzQDrr+1TQ2WCXiSuesXVWzAwX6Q=; b=R83R793l5tI1FDIlyDQR37X1D335eNo12t7F4agHHWAO8BbadbWQoHMkVm684HJbf7UtOH e7JBIkzUiY5n4RTBTVHySUR8BuUo1NXd1+a19KLCIs9d8vs4nC7xkgtAaZsclGrsx1UHmD m9x7XIF1uarn3XVC8mfODisowgBu1wQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1650527433; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=CA8kHCu+RuJ2Qz5MzQDrr+1TQ2WCXiSuesXVWzAwX6Q=; b=uE+LB8CDSh9IYEtB/WpE2lFzFgVxIThKWYKuv1AfqKjsQfGK4y/9BnkgKHTGIC4v/1Nlm4 xiQ72q3JPJSHkEAQ== Received: from alsa1.suse.de (alsa1.suse.de [10.160.4.42]) by relay2.suse.de (Postfix) with ESMTP id 758962C15A; Thu, 21 Apr 2022 07:50:33 +0000 (UTC) Date: Thu, 21 Apr 2022 09:50:33 +0200 Message-ID: From: Takashi Iwai To: Mark Brown Cc: Jaroslav Kysela , Takashi Iwai , Shuah Khan , alsa-devel@alsa-project.org, linux-kselftest@vger.kernel.org Subject: Re: [PATCH] selftests: alsa: Start validating control names In-Reply-To: <20220420203320.3035329-1-broonie@kernel.org> References: <20220420203320.3035329-1-broonie@kernel.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/25.3 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.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