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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A4B50C433F5 for ; Mon, 7 Mar 2022 09:42:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237553AbiCGJnY (ORCPT ); Mon, 7 Mar 2022 04:43:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238539AbiCGJid (ORCPT ); Mon, 7 Mar 2022 04:38:33 -0500 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09D6D45078; Mon, 7 Mar 2022 01:32:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1646645573; x=1678181573; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=qOTDz0USKGfY7/VVrIyvvAYOkFRB9THq3FS4Y8cCEpI=; b=PFmi+yS9XX/4IjJdTVkq6UXukdUiKggJif34aIKiSJo8pEevEehuzGxu bfLhpLmf6Lj3bKpgnYnQ5U81OSA0cd1X6EA5ieEUFd8mp/HQ7K+/hMZEt 0X3GKtRxzD5B0K6+EB6ElRQhQidcHvs4vKeD3jXx37iFMsQ2pTbKUmSwM KLn1f071CVAK41lPif4O2gjAHnuimLz3+IhNAY410y+v7u1POFknf18u9 M4RZkD+9eKV43F5R6htPvHzzNrG3B/ckGxUhAN/nxFDglv2ilytvp3fVg 7j3yZgfXZYON2uE1o6y8mREzTYdKrD4E1aQj2FokXV1O8Uist27qxZwFK Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10278"; a="253177707" X-IronPort-AV: E=Sophos;i="5.90,161,1643702400"; d="scan'208";a="253177707" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Mar 2022 01:32:25 -0800 X-IronPort-AV: E=Sophos;i="5.90,161,1643702400"; d="scan'208";a="509651189" Received: from smile.fi.intel.com ([10.237.72.59]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Mar 2022 01:32:22 -0800 Received: from andy by smile.fi.intel.com with local (Exim 4.95) (envelope-from ) id 1nR9iL-00Cgk7-2j; Mon, 07 Mar 2022 11:31:37 +0200 Date: Mon, 7 Mar 2022 11:31:36 +0200 From: Andy Shevchenko To: Bjorn Andersson Cc: Sakari Ailus , Rob Herring , Daniel Scally , Heikki Krogerus , "Rafael J. Wysocki" , Hans de Goede , linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Dmitry Baryshkov Subject: Re: [PATCH v3 1/6] device property: Helper to match multiple connections Message-ID: References: <20220303223351.141238-1-bjorn.andersson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org On Sun, Mar 06, 2022 at 08:18:24PM -0600, Bjorn Andersson wrote: > On Fri 04 Mar 07:52 CST 2022, Andy Shevchenko wrote: > > On Fri, Mar 04, 2022 at 03:41:33PM +0200, Sakari Ailus wrote: ... > > I have checked vsnprintf() and indeed, it expects to have the size is 0 when > > the resulting buffer pointer is NULL, and it doesn't do any additional checks. > > Per the vsnprintf() semantics it's not the destination buffer being NULL > that's significant, but rather just the length being 0 that matters. Actually the main point is to have buffer to be NULL. But at the same time size also has to be 0. When the size is 0, but buffer is not NULL, it's a different story. > To follow that, I should fill @matches_len entries in @matches and then > just continue counting without storing anything in @matches. > > But that won't work in this case, because in the event that the @match > function returns something that has to be freed (such as the refcounted > objects returned by the typec_mux code), dropping this in favor of just > counting it would cause memory/reference leaks. > > As such, I think this should differ in that @matches = NULL is > significant, and it's nice to not have matches_len turn negative/bogus > in the count case. > > So I like your suggestion. -- With Best Regards, Andy Shevchenko