Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1389168ybi; Fri, 12 Jul 2019 15:12:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqwzSsL+s9PnwOZBkCgwHac8suodZ4OQifJmltFcgoWjxdDY1WpeEZ5+vyq3xNbicwtBiexM X-Received: by 2002:a17:90a:9b08:: with SMTP id f8mr14785449pjp.103.1562969538888; Fri, 12 Jul 2019 15:12:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562969538; cv=none; d=google.com; s=arc-20160816; b=icduCiXBTMuPnC99pJN7NP+QdUm8uY5SlxS6+XnzYzVRULdDwSnjusOMgBEo2+urCe pi6N3gAvCCsG9WHz9pBb32ybHAhReNPfn39H576ZDALHg5LTQhsi1aFYcVV12yW3aZOM He+rS2Fe9J1FZgR1DJcxZCeHeNwp7iHdeeoM5Zac3znFSWudsDQNo7xWI4Z0Buzlt5Yu E9j0lNRTxb6h3KnPJ6N1ZnFSztK2/n34Wxof2YsPM72O339AsWtU/mgQKU7lIx9c22WS vCmK/13JSPraJx7qZUG9F8BbL2BANrGD5ULn658HwPLp4WeoedlDgsLVe4gobIPRdiao /lkQ== 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=XsnB/TZoLsd2HUVavF7JoXCpZGTGAOdju96E51/6tAY=; b=dr9Rkdliu1zeUDkBCPlK4DyyhbDJOQsQQftpX6S0gIgJKWgpVxYPrsvP9WU7n0r5nI hOEgUi+jyy9SAmGgMPlZPmSfWCBZwWn3LHnlfrXzBuZkH+mzjWVLijd8JpcuYErCk7Ff I0z4s3iOK1D2OdGrifxmpWanN62q2RTkDSJ8Ybhy/WFqUf5BCyNfPHo5uN6h6tls9s4x 00j/WwVAAsyx2+UJTqILSQxsAL5FlmqR2v0eaO5lnTB7H6THguAUyhNeKdd6d5MkyUM+ D7suu7mSoyub66mvQTHVUuCafvweANaI8EcetCx2RmKpcd0GD7c+UyfPODqn0csbBTdV EsGg== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 69si2782790pge.101.2019.07.12.15.12.03; Fri, 12 Jul 2019 15:12:18 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728062AbfGLWLb (ORCPT + 99 others); Fri, 12 Jul 2019 18:11:31 -0400 Received: from smtp4-g21.free.fr ([212.27.42.4]:8534 "EHLO smtp4-g21.free.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727362AbfGLWLb (ORCPT ); Fri, 12 Jul 2019 18:11:31 -0400 Received: from [192.168.1.91] (unknown [77.207.133.132]) (Authenticated sender: marc.w.gonzalez) by smtp4-g21.free.fr (Postfix) with ESMTPSA id 542C419F574; Sat, 13 Jul 2019 00:11:12 +0200 (CEST) Subject: Re: [PATCH v3] media: si2168: Refactor command setup code To: Mauro Carvalho Chehab , Brad Love Cc: 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> From: Marc Gonzalez Message-ID: <10f064c5-1634-c9f9-fcc9-6ab51b7f8f0b@free.fr> Date: Sat, 13 Jul 2019 00:11:12 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: <20190712144537.2bad2482@coco.lan> Content-Type: text/plain; charset=utf-8 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 12/07/2019 19:45, Mauro Carvalho Chehab wrote: > Brad Love escreveu: > >> On 04/07/2019 05.33, Marc Gonzalez wrote: >> >>> +#define CMD_SETUP(cmd, args, rlen) \ >>> + cmd_setup(cmd, args, sizeof(args) - 1, rlen) >>> + >> >> This is only a valid helper if args is a null terminated string. It just >> so happens that every instance in this driver is, but that could be a >> silent pitfall if someone used a u8 array with this macro. > > Actually, it is uglier than that. If one writes something like: > > char buf[20]; > > buf[0] = 0x20; > buf[1] = 0x03; > > CMD_SETUP(cmd, buf, 0); > > // some other init, up to 5 values, then another CMD_SETUP() I'm not sure what you mean in the // comment. What kind of init? Why up to 5 values? Why another CMD_SETUP? > sizeof() will evaluate to 20, and not to 2, with would be the > expected buffer size, and it will pass 18 random values. > > 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.) 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... Or maybe there's a GCC extension to test that an argument is a string literal... Regards.