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.3 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 5176BC742D2 for ; Sun, 14 Jul 2019 18:31:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3887A205F4 for ; Sun, 14 Jul 2019 18:31:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728654AbfGNSbS (ORCPT ); Sun, 14 Jul 2019 14:31:18 -0400 Received: from smtp.gentoo.org ([140.211.166.183]:48000 "EHLO smtp.gentoo.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728218AbfGNSbS (ORCPT ); Sun, 14 Jul 2019 14:31:18 -0400 Received: from [IPv6:2001:a62:1aa0:1f01:8bef:1c55:1564:aa8] (unknown [IPv6:2001:a62:1aa0:1f01:8bef:1c55:1564:aa8]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: zzam) by smtp.gentoo.org (Postfix) with ESMTPSA id DEB7A347B24; Sun, 14 Jul 2019 18:31:15 +0000 (UTC) Subject: Re: [PATCH v3] media: si2168: Refactor command setup code To: Mauro Carvalho Chehab , Marc Gonzalez Cc: Brad Love , Antti Palosaari , =?UTF-8?Q?Jonathan_Neusch=c3=a4fer?= , linux-media , LKML , MSM , Bjorn Andersson References: <544859b5-108a-1909-d612-64f67a02aeec@free.fr> <20190712144537.2bad2482@coco.lan> <10f064c5-1634-c9f9-fcc9-6ab51b7f8f0b@free.fr> <20190713070256.3495de51@coco.lan> From: Matthias Schwarzott Message-ID: <13f74614-69b8-00e1-2072-ba390d5aa2cb@gentoo.org> Date: Sun, 14 Jul 2019 20:31:18 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: <20190713070256.3495de51@coco.lan> Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 7bit Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Am 13.07.19 um 12:02 schrieb Mauro Carvalho Chehab: > Em Sat, 13 Jul 2019 00:11:12 +0200 > Marc Gonzalez escreveu: > >> On 12/07/2019 19:45, Mauro Carvalho Chehab wrote: >> >>> Brad Love escreveu: >>> >>> IMHO, using sizeof() here is a very bad idea. >> >> You may have a point... >> (Though I'm not proposing a kernel API function, merely code >> refactoring for a single file that's unlikely to change going >> forward.) > > Yes, I know, but we had already some bugs due to the usage of > sizeof() on similar macros at drivers in the past. > >> It's also bad form to repeat the cmd size (twice) when the compiler >> can figure it out automatically for string literals (which is 95% >> of the use-cases). >> >> I can drop the macro, and just use the helper... > > The helper function sounds fine. > >> >> Or maybe there's a GCC extension to test that an argument is a >> string literal... > > If this could be evaluated by some advanced macro logic that > would work not only with gcc but also with clang, then a > macro that does what you proposed could be useful. > > There are some ways to check the type of a macro argument, but I'm > not sure if are there any way for it to distinguish between a > string constant from a char * array. > Maybe something like this will prevent compilation if the argument is no string literal: #define CMD_SETUP(cmd, args, rlen) \ cmd_setup(cmd, args "", sizeof(args) - 1, rlen) Another idea is a check like: #define CMD_SETUP(cmd, args, rlen) \ do { \ BUILD_BUG_ON(#args[0] != "\""); \ cmd_setup(cmd, args "", sizeof(args) - 1, rlen) \ } while(0) Regards Matthias