Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7463143imu; Thu, 31 Jan 2019 10:29:48 -0800 (PST) X-Google-Smtp-Source: ALg8bN6CuyBBKAZN8cVl4nrgRE8MCGViTpWFMRYp6P6IkEik9AHaCi0Pv9qz1xd2Dz3PkE0+sRHe X-Received: by 2002:a62:4e16:: with SMTP id c22mr35330780pfb.167.1548959388337; Thu, 31 Jan 2019 10:29:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548959388; cv=none; d=google.com; s=arc-20160816; b=JlajhiRhp5/A4HzDtutLlstgjIZOguBwU73ajgWYBpOwhJKMO2hVEntzfKHuJIirSV fhX1og0eVDfE5Y9/VGyvtsM523SbX3JtKRU2x3+j9GLKKd07xiY2tpgoSPsi1SF2IzoH tqQBw2C5TwccMp3HdbwNvhRNxGKeUXms7x0ONGR8A3LsHk1V9mTvgEb5B/rlbfFLDJUc 4XYZinL9BD5LRLlYhRizXO3yAPAg/NY2GTB15JNLn+C2iSwb9MJmWpQvjeN5mwZ3HVqm K/gVmB0ey5xKYRazSziH8iEzdUPcYTzMpOpxWSz48px/scxHLseO7RmQSXGDhJ/ZrzBl gwtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=pjQkOgBYwAUPXck63NpVQVXsoSCG7g1qFwUH7WO8meM=; b=nM00WQd3sSEagMtSPti3/YBqJp9jlCEqliPvcH7rwSBaBvlQ+uulTqBBC2+igaatdn RkHey+F9Cp3SnqDApA0LNhS05UTfIPFGYopBWMsIi/+NwsTL6D38TRhL8BMJPab1Fxmu AlWiyiAA37XS0Pc1PIl1/Qx12sC3RBjkHqfAzOMAKRTF1AEonH5tMR7BO3ayWTClZ42f XV9zpvTQrg6Hqzz5ouSaQo3iUNSSZfXa5xiNvklNxCiooBT4Mco4ov3jl1LaDT5UJvv7 +LB1xR/yY8TExyjx0WqcW7CBoNJ02pLMrXcqnpn3/nj5pK/akz311NgP1ssYvJVggTcT nYTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=l4BtF2ED; 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 q16si4797058pgh.185.2019.01.31.10.29.32; Thu, 31 Jan 2019 10:29:48 -0800 (PST) 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; dkim=fail header.i=@gmail.com header.s=20161025 header.b=l4BtF2ED; 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 S1728270AbfAaSWQ (ORCPT + 99 others); Thu, 31 Jan 2019 13:22:16 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:43652 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727301AbfAaSWQ (ORCPT ); Thu, 31 Jan 2019 13:22:16 -0500 Received: by mail-pl1-f195.google.com with SMTP id gn14so1832353plb.10; Thu, 31 Jan 2019 10:22:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=pjQkOgBYwAUPXck63NpVQVXsoSCG7g1qFwUH7WO8meM=; b=l4BtF2ED7pt2g0hp+GnCEsyFvEw0mnayLAUPjLhGQd7KbvjAgTqJooK7OM7TJe/qYD r/xGbRrrIHW/yNDq0uPicV3j2n1jObYQT6P+zvM1lmo+zdgiLz64ojCwklER0MHITiH+ /bkyRut0eKIMePXFsLwVJpg/myn0GC4/Ewdg9/5ip9Efge9+VH/98MlNnJcx9fD6845B zZ/KhLyxJSbXFQokUjPgIkczjz0MIKFIc6t6WSP5cyqehggZPV3iCy+HTVJC/UfY3zQT +91M32MxJ0T4zv0F47eNogU9S02+wvekCzmSx4NcIfqijCC4h76j/vNvoS7ZUCbYdBqG vfHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to:user-agent; bh=pjQkOgBYwAUPXck63NpVQVXsoSCG7g1qFwUH7WO8meM=; b=Lu/OSwRavS2l/SsDrxPiEvSj+CEmmsR6TEp0iF/KdJbysqtVdHx0KORrwF8jxcZN6S leygLrYiG8kP912wi2pBkCtEqv4wNqpzxca+5IkAF4xjeZwnrZgN8rUM5d/4KVqKLq+z d0UYjgXL7NgzdHkFCaRTlMsly452hloitI7clx7AUKISNP0iKxChgt5lTpUG8pfBfXZo Va5o8TLR3SkwIozDf8tzFSaQvvEsvgi2mZs4bq05aizGhgXRgCmXu4QkGpV59IIxLRFP v0tvImqZz0rUzgWpGApSaCvfNBJcnIK78L1V22+19X/ddWVYDdbvLCm/xENU6dtztK2j kIng== X-Gm-Message-State: AJcUukdp5HJe//ryth44NNwn9OX4CHvoSIdFYTYkuOm+7twfwgbv7NK0 ycokioNVov7+xCjPqOQF+ATRCtq7 X-Received: by 2002:a17:902:d697:: with SMTP id v23mr24245041ply.261.1548958935554; Thu, 31 Jan 2019 10:22:15 -0800 (PST) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id m198sm6310255pga.10.2019.01.31.10.22.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 31 Jan 2019 10:22:15 -0800 (PST) Date: Thu, 31 Jan 2019 10:22:13 -0800 From: Guenter Roeck To: Greg KH Cc: Kyle Tso , heikki.krogerus@linux.intel.com, badhri@google.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] usb: typec: tcpm: Export partner Source Capabilities Message-ID: <20190131182213.GB17285@roeck-us.net> References: <20190131035411.53576-1-kyletso@google.com> <20190131070238.GA4500@kroah.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190131070238.GA4500@kroah.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 31, 2019 at 08:02:38AM +0100, Greg KH wrote: > On Thu, Jan 31, 2019 at 11:54:11AM +0800, Kyle Tso wrote: > > Provide a function to get the partner Source Capabilities. > > > > Signed-off-by: Kyle Tso > > --- > > drivers/usb/typec/tcpm/tcpm.c | 23 +++++++++++++++++++++++ > > include/linux/usb/tcpm.h | 1 + > > 2 files changed, 24 insertions(+) > > > > diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c > > index f1d3e54210df..29cd84ba9960 100644 > > --- a/drivers/usb/typec/tcpm/tcpm.c > > +++ b/drivers/usb/typec/tcpm/tcpm.c > > @@ -4494,6 +4494,29 @@ int tcpm_update_sink_capabilities(struct tcpm_port *port, const u32 *pdo, > > } > > EXPORT_SYMBOL_GPL(tcpm_update_sink_capabilities); > > > > +/* > > + * Don't call this function in interrupt context. Caller needs to free the > > + * memory itself. > > + */ > > +int tcpm_get_partner_src_caps(struct tcpm_port *port, u32 **src_pdo) > > +{ > > + unsigned int nr_pdo; > > + > > + if (port->nr_source_caps == 0) > > + return -ENODATA; > > + > > + *src_pdo = kcalloc(port->nr_source_caps, sizeof(u32), GFP_KERNEL); > > + if (!src_pdo) > > + return -ENOMEM; > > + > > + mutex_lock(&port->lock); > > + nr_pdo = tcpm_copy_pdos(*src_pdo, port->source_caps, > > + port->nr_source_caps); > > + mutex_unlock(&port->lock); The mutex use here suggests that the data can be updated while being copied. But that suggests that port->nr_source_caps can change as well and may no longer be current after mutex_lock(). > > + return nr_pdo; > > +} > > +EXPORT_SYMBOL_GPL(tcpm_get_partner_src_caps); > > We don't add new functions that no one uses :( > I am also concerned about the API itself; passing a pointer to be freed by the caller invites memory leaks. Guenter