Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750869AbeAPHET (ORCPT + 1 other); Tue, 16 Jan 2018 02:04:19 -0500 Received: from mail-he1eur01on0073.outbound.protection.outlook.com ([104.47.0.73]:31968 "EHLO EUR01-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750738AbeAPHEP (ORCPT ); Tue, 16 Jan 2018 02:04:15 -0500 From: Oleksandr Shamray To: Julia Cartwright 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" , Vadim Pasternak , system-sw-low-level , "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 v16 1/4] drivers: jtag: Add JTAG core driver Thread-Topic: [patch v16 1/4] drivers: jtag: Add JTAG core driver Thread-Index: AQHTi8gAQk/zPk1po0qpb7vtMqL/o6N1bbsAgACmTjA= Date: Tue, 16 Jan 2018 07:04:09 +0000 Message-ID: References: <1515776909-29894-1-git-send-email-oleksandrs@mellanox.com> <1515776909-29894-2-git-send-email-oleksandrs@mellanox.com> <20180115205142.GD2818@kryptos.localdomain> In-Reply-To: <20180115205142.GD2818@kryptos.localdomain> Accept-Language: en-US, uk-UA Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=oleksandrs@mellanox.com; x-originating-ip: [79.135.198.29] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;AM4PR0501MB2642;7:dmJx1U0Z/Z2dLIgpR0at2B9d0AEGpchF80HVd/hSpDtqgZkwBSTaLU/dKrioNxymlbIMPth26lmsHAJHBIYzBll+23zW1WaxdEXccEBwVrgCiwhl7qHo/9mF5A8sS7hpOs54ECuKMp+sQ4jApv6bUBT6vhDlv2vuBYqzid9tkHXCiJuxyxdI1DTiEIVzl5YrN/muioPHZP5+jxElMQAaZf2LPGN0Bp9l4vnjImi1AHWnPBolqw1CsYqGbcKWr22i x-ms-exchange-antispam-srfa-diagnostics: SSOS;SSOR; x-ms-office365-filtering-correlation-id: 4305f632-4dd0-4875-22ff-08d55caf574e x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(5600026)(4604075)(3008032)(48565401081)(2017052603307)(7153060)(7193020);SRVR:AM4PR0501MB2642; x-ms-traffictypediagnostic: AM4PR0501MB2642: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(143289334528602)(9452136761055)(65623756079841)(258649278758335)(42262312472803); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(6040470)(2401047)(8121501046)(5005006)(3002001)(10201501046)(93006095)(93001095)(3231023)(944501161)(6055026)(6041268)(20161123564045)(20161123558120)(20161123562045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:AM4PR0501MB2642;BCL:0;PCL:0;RULEID:(100000803101)(100110400095);SRVR:AM4PR0501MB2642; x-forefront-prvs: 0554B1F54F x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(346002)(396003)(39380400002)(39860400002)(366004)(376002)(189003)(199004)(13464003)(24454002)(7736002)(5250100002)(106356001)(6436002)(2900100001)(9686003)(3660700001)(8676002)(97736004)(74316002)(2906002)(105586002)(68736007)(305945005)(5660300001)(316002)(8936002)(102836004)(54906003)(55016002)(26005)(3280700002)(86362001)(81166006)(81156014)(229853002)(76176011)(53936002)(14454004)(478600001)(53546011)(4326008)(33656002)(7696005)(66066001)(3846002)(7416002)(59450400001)(25786009)(6916009)(2950100002)(99286004)(6116002)(107886003)(6246003)(6506007);DIR:OUT;SFP:1101;SCL:1;SRVR:AM4PR0501MB2642;H:AM4PR0501MB2194.eurprd05.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; x-microsoft-antispam-message-info: xcYOY7jRcQPHKNzrF8tDGbUoXGKlwe3XCSfoFaOMRGmrPv9q5hwck5F+6lQz7qXE0sU9SFH/rT22c5y7ZvEQ/g== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="koi8-r" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4305f632-4dd0-4875-22ff-08d55caf574e X-MS-Exchange-CrossTenant-originalarrivaltime: 16 Jan 2018 07:04:09.5313 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR0501MB2642 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: Hi Julia > -----Original Message----- > From: Julia Cartwright [mailto:juliac@eso.teric.us] > Sent: 15 ?????? 2018 ?. 22:52 > 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; Vadim > Pasternak ; system-sw-low-level 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 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