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=-7.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY autolearn=ham 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 9167AC28CC0 for ; Wed, 29 May 2019 15:36:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6E17623A45 for ; Wed, 29 May 2019 15:36:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726253AbfE2Pga (ORCPT ); Wed, 29 May 2019 11:36:30 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:53726 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725914AbfE2Pg3 (ORCPT ); Wed, 29 May 2019 11:36:29 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: ezequiel) with ESMTPSA id 151FF260F39 Message-ID: <100592967e3c3546b4dcbbb8a0369297b27fa8e8.camel@collabora.com> Subject: Re: [PATCH] media: v4l2: Initialize mpeg slice controls From: Ezequiel Garcia To: Hans Verkuil , Boris Brezillon , Mauro Carvalho Chehab , Hans Verkuil , Laurent Pinchart , Sakari Ailus , linux-media@vger.kernel.org Cc: kernel@collabora.com Date: Wed, 29 May 2019 12:36:20 -0300 In-Reply-To: References: <20190503114221.28469-1-boris.brezillon@collabora.com> Organization: Collabora Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.30.5-1 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org On Wed, 2019-05-29 at 16:41 +0200, Hans Verkuil wrote: > On 5/3/19 1:42 PM, Boris Brezillon wrote: > > Make sure the default value at least passes the std_validate() tests. > > > > Signed-off-by: Boris Brezillon > > --- > > drivers/media/v4l2-core/v4l2-ctrls.c | 20 +++++++++++++++++++- > > 1 file changed, 19 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c > > index b1ae2e555c68..19d40cc6e565 100644 > > --- a/drivers/media/v4l2-core/v4l2-ctrls.c > > +++ b/drivers/media/v4l2-core/v4l2-ctrls.c > > @@ -1461,7 +1461,14 @@ static bool std_equal(const struct v4l2_ctrl *ctrl, u32 idx, > > static void std_init(const struct v4l2_ctrl *ctrl, u32 idx, > > union v4l2_ctrl_ptr ptr) > > { > > - switch (ctrl->type) { > > + struct v4l2_ctrl_mpeg2_slice_params *p_mpeg2_slice_params; > > + > > + /* > > + * The cast is needed to get rid of a gcc warning complaining that > > + * V4L2_CTRL_TYPE_MPEG2_SLICE_PARAMS is not part of the > > + * v4l2_ctrl_type enum. > > + */ > > + switch ((u32)ctrl->type) { > > case V4L2_CTRL_TYPE_STRING: > > idx *= ctrl->elem_size; > > memset(ptr.p_char + idx, ' ', ctrl->minimum); > > @@ -1486,6 +1493,17 @@ static void std_init(const struct v4l2_ctrl *ctrl, u32 idx, > > case V4L2_CTRL_TYPE_U32: > > ptr.p_u32[idx] = ctrl->default_value; > > break; > > + case V4L2_CTRL_TYPE_MPEG2_SLICE_PARAMS: > > + p_mpeg2_slice_params = ptr.p; > > + /* 4:2:0 */ > > + p_mpeg2_slice_params->sequence.chroma_format = 1; > > + /* 8 bits */ > > + p_mpeg2_slice_params->picture.intra_dc_precision = 0; > > + /* interlaced top field */ > > + p_mpeg2_slice_params->picture.picture_structure = 1; > > + p_mpeg2_slice_params->picture.picture_coding_type = > > + V4L2_MPEG2_PICTURE_CODING_TYPE_I; > > Oops, this isn't complete. It should still zero the p_mpeg2_slice_params > struct first. Right now any fields not explicitly set just have whatever > was in memory. > > Can you post a patch fixing this? > > I was wondering if we want to zero all the cases, and not just the struct types ones. Or a different approach would be to define statically-allocated default structs, and init-assign to them. Although this take more space, and has no benefits, except maybe code clarity. OTOH, I can push a quick fix if you want, just zeroing this struct.