From patchwork Mon Jan 25 12:35:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 8108191 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 999ADBEEE5 for ; Mon, 25 Jan 2016 12:36:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D1BBF202E9 for ; Mon, 25 Jan 2016 12:36:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F40DA202E6 for ; Mon, 25 Jan 2016 12:36:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756977AbcAYMgv (ORCPT ); Mon, 25 Jan 2016 07:36:51 -0500 Received: from mga02.intel.com ([134.134.136.20]:59283 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756961AbcAYMgt (ORCPT ); Mon, 25 Jan 2016 07:36:49 -0500 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP; 25 Jan 2016 04:36:48 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.22,344,1449561600"; d="scan'208";a="897812060" Received: from paasikivi.fi.intel.com ([10.237.72.42]) by orsmga002.jf.intel.com with ESMTP; 25 Jan 2016 04:36:47 -0800 Received: from nauris.fi.intel.com (nauris.localdomain [192.168.240.2]) by paasikivi.fi.intel.com (Postfix) with ESMTP id E83F72007D; Mon, 25 Jan 2016 14:36:45 +0200 (EET) Received: by nauris.fi.intel.com (Postfix, from userid 1000) id A1BCC201DC; Mon, 25 Jan 2016 14:35:06 +0200 (EET) From: Sakari Ailus To: linux-media@vger.kernel.org Cc: laurent.pinchart@ideasonboard.com, hverkuil@xs4all.nl Subject: [PATCH v2 1/1] v4l: libv4l2subdev: Precisely convert media bus string to code Date: Mon, 25 Jan 2016 14:35:06 +0200 Message-Id: <1453725306-4047-1-git-send-email-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.1.0.231.g7484e3b Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Any character beyond the fist `length' characters in the mbus_formats strings are ignored, causing incorrect matches if the format entry starts with but isn't equal to the passed format. Signed-off-by: Sakari Ailus Reviewed-by: Laurent Pinchart --- since v1: - Use mbus_formats[i].name[length] == '\0' instead of comparing strlen() result. utils/media-ctl/libv4l2subdev.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/utils/media-ctl/libv4l2subdev.c b/utils/media-ctl/libv4l2subdev.c index 33c1ee6..dc2cd87 100644 --- a/utils/media-ctl/libv4l2subdev.c +++ b/utils/media-ctl/libv4l2subdev.c @@ -769,14 +769,12 @@ enum v4l2_mbus_pixelcode v4l2_subdev_string_to_pixelcode(const char *string, unsigned int i; for (i = 0; i < ARRAY_SIZE(mbus_formats); ++i) { - if (strncmp(mbus_formats[i].name, string, length) == 0) - break; + if (strncmp(mbus_formats[i].name, string, length) == 0 + && mbus_formats[i].name[length] == '\0') + return mbus_formats[i].code; } - if (i == ARRAY_SIZE(mbus_formats)) - return (enum v4l2_mbus_pixelcode)-1; - - return mbus_formats[i].code; + return (enum v4l2_mbus_pixelcode)-1; } static struct {