Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3326500ybi; Sun, 14 Jul 2019 11:31:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqwl32rP1YKiSBE9prGAg70x5C22jr+JTuUwEhUjdL4nxIIk97Itj2TskKzjtZioVcPisMVX X-Received: by 2002:a63:3d8f:: with SMTP id k137mr23093111pga.337.1563129119413; Sun, 14 Jul 2019 11:31:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563129119; cv=none; d=google.com; s=arc-20160816; b=NKwpuikutF9AfqveXNPBPFvtaDy74iTlUXTlGM/ncKGxTWfGx7fNhIAPKEKx2I3ITX KqvvvRkrgPkkWY/xpIUQY+9uf6IuLMfxjkI+FO/IU1hYGldx+4WnJXwE19ez0Led6x6V BM2wRFxyKOmS3OgcdpX6jAuIMWrW7BRStIWWt/suvLii56nZRwaN2i1fOOqYddwjPudK frQT3KuFpd/tixX27Y1nTZN4DlCtuHde/J/GLlivwWZvi5LKUgaN9Ql6kGq3cXtAK6ix 77bdqtBx6TsL33IIvG/iFTjJdBQ61fCxO8lufo3SNOfZ64jlW7S988P7Z8ZKsThreOQe +ymg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=Ft4PUfWkwOG15G9gCLmINQeEKaoP3ogwgdVjyEJubwI=; b=WZho5cfw7DBt3kVzND28pJF4vBbknSrhAVBmGm/VhuOratV+WbK8oYGYhd532l1CQt /t7uD5x5w/JpF4nfKuoOEMhRvICEtL8hWTLjjut+PEVLQYQW4Do4prPk9s8WSbLCvjQp XHbfW1xx9fpvD4KY1qguC6MqpgcTJwAvnkkTU4JJkx4u4WxmZ+h4P2xAItG6d04sbS5s KXj2CXWafQ3BRLEVdf+AF7khhD3/q94S/Yi7nWvytCvgKpRho1PZKUtQ1oRx9/hvxYnO B5i6UR64k5gyqG9D07s+1/xyizslCyRoYCWGu1EBusEKBnHIPMGrB88F/NSiWW/H1KCo kmWQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gentoo.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 24si14220432pgw.107.2019.07.14.11.31.43; Sun, 14 Jul 2019 11:31:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gentoo.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728712AbfGNSbS (ORCPT + 99 others); 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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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