Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp3665457imj; Tue, 12 Feb 2019 02:36:52 -0800 (PST) X-Google-Smtp-Source: AHgI3IZT+57lFanhWPvLLciXpIdkUKiKDeljNvTC0IBmmxFsaEN1fhaOviMwr6isYa6ws95N1C61 X-Received: by 2002:a62:1c86:: with SMTP id c128mr3427740pfc.54.1549967812341; Tue, 12 Feb 2019 02:36:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549967812; cv=none; d=google.com; s=arc-20160816; b=BGY/CnS4owqLh0CA1JWhZH8iMA2dsi1lOLYh0KivtpxhfbSrQQEhkXZ0bFulXMgggC 4ZwQ/Ik9+Jx1t3poh04KHjv/KxuMoCHpLo+EdzZDq3YBMACvHHUF239y5ZaWdMpoWlSW V0IlmeRDYvM7a2ps/Ud9s0OBMd52PdHNIQ98yc7W1mUHFv/ICFmX3YYtfxbpKQDHmfZj rTI2c6A5f8sEs/+MM/XJ5Z2yfBJX0tX1YrOKrwTpyDe7MMAvFtUrQ8V4Q3R2J+d4t0so WA9dZ8rlYnu8mLbFd8IpXJ31Y+/MmTWuOzVn8OpfKCqFj+99tzQmsk/2KL70ahYJhq83 LZtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=GMp23AgSoT/MoD52DueN6r2g7Edyg9sRa2l4h5O+Nf4=; b=r3/7t7wC3lbprG8UMTUyU6D0jG2zKEC4YhNzUf6eMy2yaOHkeyvd8+p5tDDvUJCmys /btHNXBkqNU7db3J/+cCgYHZ4a9bmf90wDLU/oKHQgXxy347dqm1ZhzrJrEnuvlNAXkj cGHjD+9V0c9BH48UNz1i6dj8TwIfSAQKWNFao9/qnAliC44vt1H8LHOKKB38+nsHn9Fj rnz6fJpsmvTSgcHB3KU3t0Kl52T2s60v6I55DZGBK/v9JKCkNwlyAA4Hi2KDVVX1vyoE V48qNvO9Omszl+bvpKZfh6tM1/8Feannf/vlcgRn3FqnaPELjRCq0bKYNpYsTIt25/YQ 7/Vw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=qX5+Vrla; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t4si2830781pgv.168.2019.02.12.02.36.36; Tue, 12 Feb 2019 02:36:52 -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=pass header.i=@google.com header.s=20161025 header.b=qX5+Vrla; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728829AbfBLKd6 (ORCPT + 99 others); Tue, 12 Feb 2019 05:33:58 -0500 Received: from mail-qk1-f195.google.com ([209.85.222.195]:33655 "EHLO mail-qk1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727976AbfBLKd5 (ORCPT ); Tue, 12 Feb 2019 05:33:57 -0500 Received: by mail-qk1-f195.google.com with SMTP id x9so8381236qkf.0 for ; Tue, 12 Feb 2019 02:33:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=GMp23AgSoT/MoD52DueN6r2g7Edyg9sRa2l4h5O+Nf4=; b=qX5+VrlaVMhmalp/VbGGMyGV3aSvVFMkyQRCI+HBNE80awcN+TrCpuBtts19sMwf0T zGTj8WzNL5KyV0H3p+DVTVdxBExcUU9LkKV0Dr7rVQwKcBgIMX8rFsx2L4P39vbv1PdH /dVW3vS+xbVgyn9jj1eRThDbv/xGlSWhEXaQP1wXzZA3L4269iyUvqy7Tz6AkLNh+G9n FP1EF/vlBK1LblsBdNDIeZA7BqolnhT0XqaWEFeL7Lf2todn9YscRkItvH9xAgmqOPZb sWc0zolqNllYXt9QP0erwzD1efEZftBjsOseKTDZuvzdDRAyDOJJLO9Eq2LWr/8l2VvF boSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=GMp23AgSoT/MoD52DueN6r2g7Edyg9sRa2l4h5O+Nf4=; b=t+0Lpg2kcBvonmtSZggHZUo8vX+lCBmbkwkKWy0vZTP80h1YNqGxSId0i29Q9Mh9PB 841tAjSXwLzyG/hmyN6rercST2k9JrXhwAnw13L4H7YL4HTK5yb4lPcMokU93/T5m/JN NX2MpJ079yNIwZ0L9c9csuLf6u+NL68FYWEEyO2q8ryWbRGkIajmgcV7cvfoez88xIwo 3/AZ7Qz5mOAlLtUGhlURIFlD4STARWYqgtkd6/Glf3idaNfhOKQLSqli2PgQEceWLJki 1dlm8nR6DyHBfp2w1lTYkkzCLxyq9cKtSpO75bBLKsIo3wDk+L1mlx1O1TGvnNMsd3t+ si6Q== X-Gm-Message-State: AHQUAubOn+KAkcNRXO2qgaz2aDRcMc2BMXz3xHKAFxppj0rMsFgDPEz3 L7EmSQiAZiRMmR7D0Q03B3nf2cH8ootJYXUBqIxu7g== X-Received: by 2002:ae9:f809:: with SMTP id x9mr2072092qkh.84.1549967636208; Tue, 12 Feb 2019 02:33:56 -0800 (PST) MIME-Version: 1.0 References: <20190131035411.53576-1-kyletso@google.com> <20190131070238.GA4500@kroah.com> <20190131182213.GB17285@roeck-us.net> In-Reply-To: <20190131182213.GB17285@roeck-us.net> From: Kyle Tso Date: Tue, 12 Feb 2019 18:33:45 +0800 Message-ID: Subject: Re: [PATCH] usb: typec: tcpm: Export partner Source Capabilities To: Guenter Roeck Cc: Greg KH , Heikki Krogerus , Badhri Jagan Sridharan , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Feb 1, 2019 at 2:22 AM Guenter Roeck wrote: > > 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(). > Thanks for pointing out the bug. I will fix this in the next version. > > > + 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 What is the better way to implement this? How about providing a function (say "tcpm_put_partner_src_caps") for the caller to free the memory?