[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <AM4PR0501MB2194BD3F84A1E944EF335ECAB1EA0@AM4PR0501MB2194.eurprd05.prod.outlook.com>
Date: Tue, 16 Jan 2018 07:04:09 +0000
From: Oleksandr Shamray <oleksandrs@...lanox.com>
To: Julia Cartwright <juliac@....teric.us>
CC: "gregkh@...uxfoundation.org" <gregkh@...uxfoundation.org>,
"arnd@...db.de" <arnd@...db.de>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"linux-arm-kernel@...ts.infradead.org"
<linux-arm-kernel@...ts.infradead.org>,
"devicetree@...r.kernel.org" <devicetree@...r.kernel.org>,
"openbmc@...ts.ozlabs.org" <openbmc@...ts.ozlabs.org>,
"joel@....id.au" <joel@....id.au>,
"jiri@...nulli.us" <jiri@...nulli.us>,
"tklauser@...tanz.ch" <tklauser@...tanz.ch>,
"linux-serial@...r.kernel.org" <linux-serial@...r.kernel.org>,
Vadim Pasternak <vadimp@...lanox.com>,
system-sw-low-level <system-sw-low-level@...lanox.com>,
"robh+dt@...nel.org" <robh+dt@...nel.org>,
"openocd-devel-owner@...ts.sourceforge.net"
<openocd-devel-owner@...ts.sourceforge.net>,
"linux-api@...r.kernel.org" <linux-api@...r.kernel.org>,
"davem@...emloft.net" <davem@...emloft.net>,
"mchehab@...nel.org" <mchehab@...nel.org>,
Jiri Pirko <jiri@...lanox.com>
Subject: RE: [patch v16 1/4] drivers: jtag: Add JTAG core driver
Hi Julia
> -----Original Message-----
> From: Julia Cartwright [mailto:juliac@....teric.us]
> Sent: 15 января 2018 г. 22:52
> To: Oleksandr Shamray <oleksandrs@...lanox.com>
> Cc: gregkh@...uxfoundation.org; arnd@...db.de; linux-
> kernel@...r.kernel.org; linux-arm-kernel@...ts.infradead.org;
> devicetree@...r.kernel.org; openbmc@...ts.ozlabs.org; joel@....id.au;
> jiri@...nulli.us; tklauser@...tanz.ch; linux-serial@...r.kernel.org; Vadim
> Pasternak <vadimp@...lanox.com>; system-sw-low-level <system-sw-low-
> level@...lanox.com>; robh+dt@...nel.org; openocd-devel-
> owner@...ts.sourceforge.net; linux-api@...r.kernel.org;
> davem@...emloft.net; mchehab@...nel.org; Jiri Pirko
> <jiri@...lanox.com>
> Subject: Re: [patch v16 1/4] drivers: jtag: Add JTAG core driver
>
> Hello Oleksandr-
>
> I have a few comments below.
>
> On Fri, Jan 12, 2018 at 07:08:26PM +0200, Oleksandr Shamray wrote:
> > Initial patch for JTAG driver
> > JTAG class driver provide infrastructure to support hardware/software
> > JTAG platform drivers. It provide user layer API interface for
> > flashing and debugging external devices which equipped with JTAG
> > interface using standard transactions.
> >
[..]
> > + break;
> > +
> > + case JTAG_IOCXFER:
> > + if (!jtag->ops->xfer)
>
> Are all ops optional? That seems bizarre. I would have expected at least one
> callback to be required.
You right. But I'm preferred to check pointers before use it.
>
> [..]
> > +static int jtag_open(struct inode *inode, struct file *file) {
> > + struct jtag *jtag = container_of(file->private_data, struct jtag,
> > + miscdev);
> > +
> > + if (mutex_lock_interruptible(&jtag->open_lock))
> > + return -ERESTARTSYS;
> > +
> > + if (jtag->opened) {
> > + mutex_unlock(&jtag->open_lock);
> > + return -EBUSY;
> > + }
> > +
> > + nonseekable_open(inode, file);
> > + file->private_data = jtag;
>
> These two can be moved out of the lock.
Agree.
>
> > + jtag->opened = true;
> > + mutex_unlock(&jtag->open_lock);
> > + return 0;
> > +}
> > +
> > +static int jtag_release(struct inode *inode, struct file *file) {
> > + struct jtag *jtag = file->private_data;
> > +
> > + mutex_lock(&jtag->open_lock);
> > + jtag->opened = false;
> > + mutex_unlock(&jtag->open_lock);
> > + return 0;
> > +}
> > +
> > +static const struct file_operations jtag_fops = {
> > + .owner = THIS_MODULE,
> > + .open = jtag_open,
> > + .release = jtag_release,
> > + .llseek = noop_llseek,
> > + .unlocked_ioctl = jtag_ioctl,
> > +};
> > +
> > +struct jtag *jtag_alloc(size_t priv_size, const struct jtag_ops *ops)
> > +{
> > + struct jtag *jtag;
> > +
> > + jtag = kzalloc(sizeof(*jtag), GFP_KERNEL);
>
> Did you mean to allocate: sizeof(*jtag) + priv_size?
Thank, it's a mistake.
>
> > + if (!jtag)
> > + return NULL;
> > +
> > + jtag->ops = ops;
> > + return jtag;
> > +}
> > +EXPORT_SYMBOL_GPL(jtag_alloc);
> > +
> > +void jtag_free(struct jtag *jtag)
> > +{
> > + kfree(jtag);
> > +}
> > +EXPORT_SYMBOL_GPL(jtag_free);
> > +
> > +int jtag_register(struct jtag *jtag)
> > +{
> > + char *name;
> > + int err;
> > + int id;
> > +
> > + id = ida_simple_get(&jtag_ida, 0, 0, GFP_KERNEL);
> > + if (id < 0)
> > + return id;
> > +
> > + jtag->id = id;
> > +
> > + name = kzalloc(MAX_JTAG_NAME_LEN, GFP_KERNEL);
> > + if (!name) {
> > + err = -ENOMEM;
> > + goto err_jtag_alloc;
> > + }
> > +
> > + err = snprintf(name, MAX_JTAG_NAME_LEN, "jtag%d", id);
> > + if (err < 0)
> > + goto err_jtag_name;
> > +
> > + mutex_init(&jtag->open_lock);
> > + jtag->miscdev.fops = &jtag_fops;
> > + jtag->miscdev.minor = MISC_DYNAMIC_MINOR;
> > + jtag->miscdev.name = name;
> > +
> > + err = misc_register(&jtag->miscdev);
> > + if (err)
> > + dev_err(jtag->dev, "Unable to register device\n");
> > + else
> > + return 0;
> > + jtag->opened = false;
>
> Well, this code flow is just confusing.
>
> I suggest a redo with:
>
> err = misc_register(&jtag->miscdev);
> if (err) {
> dev_err(jtag->dev, "Unable to register device\n");
> goto err_jtag_name;
> }
>
> If you need to initialize 'opened', do it prior to misc_register.
>
Thanks
> Thanks,
> Julia
Thanks for Review.
Br,
Oleksandr
Powered by blists - more mailing lists