Received: by 10.223.148.5 with SMTP id 5csp6253152wrq; Wed, 17 Jan 2018 11:15:36 -0800 (PST) X-Google-Smtp-Source: ACJfBotJS3N89Edot/U5m4BYdm5U70YnZwP7r4xju6XAybMrsk5W37p6Yljkl7UVd/QrOjem9PSw X-Received: by 10.101.98.216 with SMTP id m24mr33758354pgv.100.1516216536564; Wed, 17 Jan 2018 11:15:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516216536; cv=none; d=google.com; s=arc-20160816; b=cSJbplp63MBpTSx0+U5q4g7uVtz07LsmNmg58w5wGS4BydSmFJK1vhWRpZNmyWcFMR viLF8ihXo7U6MHZC532ZoR4R8vANkfXBOVW2YOAWH05V3xbqTLdimTd4gVvGtsRcEFjf FRqkZ3WdD8hZKnVUErJw8xPWuF1XtoguMvnt13mhFmgLT9TjjG+LSBzKkAZI+Vx1ANN9 YjAF92RSVm9bAfZYiaXuiiefuQUrJR9xCp+ewM/qxbjxy3aqLfz8yauh+hUt92diloGN VYm4YubwhzNXvM7cRmnS7By9i7j9VQHAoF3K49BZqEPDC/JR4g65xvpbjJ0T9cRnlc1X Xm2w== 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:arc-authentication-results; bh=kdKsnvOgsUQfS4iX2mzbXVFGJGbigQOq/fiBZYDtoMs=; b=Px/RgHyl1l6WG4AE5AV0QjL1aTn/1Vi0S3uY61dh13XzG5z6KkVSOWq0cppCOSK+9n XKWSaKBmDGv3tO/+0F/rfTKObrtxq05QZw1dt2coIiciLfjj/ZFuWeTWnTsfmf9+GMVj aSAkStGVRkOKLnl1dtx3lVCqk7GKkbgXrlQa9587y3gn8YfcqnX4YkZRQ/nsE5AdTAKl +6mKs3h09W4LCxCdZMtSj0jHBMUWUzHWbdF0YP9WhFi8vWnXB9OGU1T+tx330+rNzc9v VturHs28dqDQLEeezj3yL+C7d6W0eCWP08aL8AIin8qkdpALcL5hHp4pB36p7gCVPhic JCFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@eso.teric.us header.s=mail header.b=JvbA48nq; 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 m21si4352262pgc.351.2018.01.17.11.15.22; Wed, 17 Jan 2018 11:15:36 -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=@eso.teric.us header.s=mail header.b=JvbA48nq; 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 S1752888AbeAQTOq (ORCPT + 99 others); Wed, 17 Jan 2018 14:14:46 -0500 Received: from eso.teric.us ([69.164.192.171]:59190 "EHLO eso.teric.us" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752100AbeAQTOn (ORCPT ); Wed, 17 Jan 2018 14:14:43 -0500 Received: from neo.teric.us (neo.teric.us [198.58.100.135]) by eso.teric.us (Postfix) with ESMTPS id C70CA1036F; Wed, 17 Jan 2018 13:14:41 -0600 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eso.teric.us; s=mail; t=1516216481; bh=kdKsnvOgsUQfS4iX2mzbXVFGJGbigQOq/fiBZYDtoMs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=JvbA48nqoDpik6SDlfRUf/W/jpWUK9bEVJQPOhFM1S9IuueneBfwci21wmUIgl/BA n6fPv+kEehX95nuV1/AxB7mmLjkFfoRk69wmO4QrvSp0uNHq6huQGv99ag3l6zKDQO EcFMF/uZlk2JgQEpsGMHlmACs6fNltfZb+q3IBm34z6idArxFO8HbjVKaGghsAx2+G 4bo44WSGRvsG4s2KrOyaXLeEJH99/xL6iFS5j2UzCSQop0M5MSW4PveAm5gofbuUKP 8Bg2cOS/D5S+DGBmrcwf1qJxzc89owEWWRhfbkwCeFeyAin0Y/zwKWzWA8x6g2BV0g LjcplWYHzZMXw== Received: by neo.teric.us (Postfix, from userid 1002) id B5C78185FDB; Wed, 17 Jan 2018 13:14:41 -0600 (CST) Date: Wed, 17 Jan 2018 13:14:41 -0600 From: Julia Cartwright To: Oleksandr Shamray Cc: gregkh@linuxfoundation.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, openbmc@lists.ozlabs.org, joel@jms.id.au, jiri@resnulli.us, tklauser@distanz.ch, linux-serial@vger.kernel.org, vadimp@mellanox.com, system-sw-low-level@mellanox.com, robh+dt@kernel.org, openocd-devel-owner@lists.sourceforge.net, linux-api@vger.kernel.org, davem@davemloft.net, mchehab@kernel.org, Jiri Pirko Subject: Re: [patch v17 1/4] drivers: jtag: Add JTAG core driver Message-ID: <20180117191441.GE2818@kryptos.localdomain> References: <1516087139-7510-1-git-send-email-oleksandrs@mellanox.com> <1516087139-7510-2-git-send-email-oleksandrs@mellanox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1516087139-7510-2-git-send-email-oleksandrs@mellanox.com> User-Agent: Mutt/1.8.3 (2017-05-23) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello Oleksandr- On Tue, Jan 16, 2018 at 09:18:56AM +0200, Oleksandr Shamray wrote: [..] > v16->v17 > Comments pointed by Julia Cartwright More review feedback below: [..] > +++ b/drivers/jtag/jtag.c [..] > +static long jtag_ioctl(struct file *file, unsigned int cmd, unsigned long arg) > +{ > + struct jtag *jtag = file->private_data; > + struct jtag_run_test_idle idle; > + struct jtag_xfer xfer; > + u8 *xfer_data; > + u32 data_size; > + u32 value; > + int err; > + > + if (!arg) > + return -EINVAL; > + > + switch (cmd) { > + case JTAG_GIOCFREQ: > + if (!jtag->ops->freq_get) > + err = -EOPNOTSUPP; Did you mean: return -EOPNOTSUPP; ? > + > + err = jtag->ops->freq_get(jtag, &value); Otherwise you're check was worthless, you'll call NULL here. Also, w.r.t. the set of ops which are required to be implemented: this isn't the right place to do the check. Instead, do it in jtag_alloc(): struct jtag *jtag_alloc(size_t priv_size, const struct jtag_ops *ops) { struct jtag *jtag; if (!ops->freq_get || !ops->xfer || ...) /* fixup condition */ return NULL; jtag = kzalloc(sizeof(*jtag) + priv_size, GFP_KERNEL); if (!jtag) return NULL; jtag->ops = ops; return jtag; } EXPORT_SYMBOL_GPL(jtag_alloc); [..] > + case JTAG_IOCXFER: [..] > + data_size = DIV_ROUND_UP(xfer.length, BITS_PER_BYTE); > + xfer_data = memdup_user(u64_to_user_ptr(xfer.tdio), data_size); > + > + if (!xfer_data) memdup_user() doesn't return NULL on error. You need to check for IS_ERR(xfer_data). > + return -EFAULT; > + > + err = jtag->ops->xfer(jtag, &xfer, xfer_data); > + if (err) { > + kfree(xfer_data); > + return -EFAULT; > + } > + > + err = copy_to_user(u64_to_user_ptr(xfer.tdio), > + (void *)(xfer_data), data_size); > + > + if (err) { > + kfree(xfer_data); > + return -EFAULT; > + } > + > + kfree(xfer_data); Move the kfree() above the if (err). > + if (copy_to_user((void *)arg, &xfer, sizeof(struct jtag_xfer))) > + return -EFAULT; > + break; > + > + case JTAG_GIOCSTATUS: > + if (!jtag->ops->status_get) > + return -EOPNOTSUPP; > + > + err = jtag->ops->status_get(jtag, &value); > + if (err) > + break; > + > + err = put_user(value, (__u32 *)arg); > + if (err) > + err = -EFAULT; put_user() returns -EFAULT on failure, so this shouldn't be necessary. [..] > --- /dev/null > +++ b/include/uapi/linux/jtag.h [..] > +/** > + * struct jtag_xfer - jtag xfer: > + * > + * @type: transfer type > + * @direction: xfer direction > + * @length: xfer bits len > + * @tdio : xfer data array > + * @endir: xfer end state > + * > + * Structure represents interface to JTAG device for jtag sdr xfer > + * execution. > + */ > +struct jtag_xfer { > + __u8 type; > + __u8 direction; > + __u8 endstate; Just to be as unambiguous as possible, considering this is ABI, I would suggest explicitly putting a padding byte here. > + __u32 length; > + __u64 tdio; > +}; Thanks, Julia