From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2E13FC43381 for ; Tue, 19 Mar 2019 14:59:46 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EA9462146E for ; Tue, 19 Mar 2019 14:59:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="AYlHhrFD"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=xilinx.onmicrosoft.com header.i=@xilinx.onmicrosoft.com header.b="ElE0lRnk" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EA9462146E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xilinx.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:In-Reply-To:References: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=5AMLb4zOeO63ktI+yvhdA+wdmsa9sazt/On4sABkdQo=; b=AYlHhrFDEHlEH5 5PJ7ibvAnQpZ7PRHT0BpVABTRUCG+YsYvsjf/gBivrSD1PXp3LHkSxu9ilrhnsbUU8bzwTHOigvkK 7w37K/7o+gJwEvcmGmHW24VntGpL3VLlAV2vL4v7AVuqnqlChUUISZA+mlxP5AWqGNcyLLEAULawc MpI9oPwqjOrqbbWjjDs9OJBB0EBAps6WkcClQC8gNWKb7Cba6lxSnieV5xBrqqX5eGzPoFBO7Vw6j 27fDqzSu5WyU0fn+F3qft4dcObgUbVrY1hHcoqAoz5h3zPJaMoF0b4FdTlwRZoblCZduFTwBYu+/7 /GY+zhxYdkxNIjPDK0Cw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h6GDM-0004x8-OU; Tue, 19 Mar 2019 14:59:40 +0000 Received: from mail-eopbgr680063.outbound.protection.outlook.com ([40.107.68.63] helo=NAM04-BN3-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h6GDJ-0004wF-NH for linux-arm-kernel@lists.infradead.org; Tue, 19 Mar 2019 14:59:38 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector1-xilinx-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=m+t7+ulKuEfpr9ofi/fwlN+isVDlgpFXn7IUDnZsrD0=; b=ElE0lRnkoGg73wNR+Zsn9KjazRyVqv/5nS9yqIMWolsMUn4Ti/ZWdNpXt7opE186n5MQ8JCgYrZId2QzF/j0IXfuKrR45O1TF9AyGg4RNMapoltU+AHPMtMbGRLxwJLdC5cHHVM4kPr2aKs+Knzo4nBmjxYcKBmryojmyozgSrE= Received: from BL0PR02MB5681.namprd02.prod.outlook.com (20.177.241.92) by BL0PR02MB5635.namprd02.prod.outlook.com (20.177.241.82) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1709.14; Tue, 19 Mar 2019 14:59:34 +0000 Received: from BL0PR02MB5681.namprd02.prod.outlook.com ([fe80::dc07:4b0:4a82:392a]) by BL0PR02MB5681.namprd02.prod.outlook.com ([fe80::dc07:4b0:4a82:392a%6]) with mapi id 15.20.1709.015; Tue, 19 Mar 2019 14:59:34 +0000 From: Dragan Cvetic To: Arnd Bergmann Subject: RE: [PATCH 04/12] misc: xilinx_sdfec: Add open, close and ioctl Thread-Topic: [PATCH 04/12] misc: xilinx_sdfec: Add open, close and ioctl Thread-Index: AQHU3kvx8x3F3XN98kC51fP21to83qYS76+AgAAPpVA= Date: Tue, 19 Mar 2019 14:59:34 +0000 Message-ID: References: <1552997064-432700-1-git-send-email-dragan.cvetic@xilinx.com> <1552997064-432700-5-git-send-email-dragan.cvetic@xilinx.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=draganc@xilinx.com; x-originating-ip: [149.199.80.133] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: c602ef86-2be4-454c-451c-08d6ac7b7fdf x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600127)(711020)(4605104)(4618075)(2017052603328)(7153060)(7193020); SRVR:BL0PR02MB5635; x-ms-traffictypediagnostic: BL0PR02MB5635: x-microsoft-antispam-prvs: x-forefront-prvs: 0981815F2F x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(366004)(396003)(39850400004)(136003)(346002)(376002)(189003)(199004)(13464003)(81166006)(81156014)(71200400001)(8676002)(99286004)(7696005)(6116002)(76176011)(53546011)(86362001)(6916009)(102836004)(6506007)(186003)(52536014)(6246003)(26005)(3846002)(14454004)(14444005)(68736007)(256004)(71190400001)(5660300002)(6436002)(478600001)(97736004)(33656002)(105586002)(305945005)(486006)(66066001)(106356001)(7736002)(476003)(316002)(53936002)(8936002)(9686003)(2906002)(54906003)(4326008)(229853002)(11346002)(446003)(25786009)(74316002)(55016002); DIR:OUT; SFP:1101; SCL:1; SRVR:BL0PR02MB5635; H:BL0PR02MB5681.namprd02.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: xilinx.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: rjSvWeXCVhRS3f5JEzbi98YgP47QefuK1GeBFZwa9WgDVfC0/uqUjp+JrtnesUIG/Uh1/KVJJiCuJwdLByzKiUNLJBiZWusun8ZZtUV5Bc/R1bZSr1sySMqyFWQfeZrn14qgtyUyWK1TLLgEZin/6B4Ii1hCOEYtonXYDBYdrmIzEUfA8GMwXC34uP9R3g4z3F7yrub+H6uavOxlvEnE72O/dkmeAnLfkSwIK51HocS53bKYjLZ8lQXhWEfTnOPnRKFNuFYjER938spN2v3k4qXBttyDk62erViR7NmuWz0f20To6BVBkjoXKD5eymsXcKQXSdaefvJJLk8rkLnWACK1LLPiLwnpfWkvZOuVUS+w0cDXOmymF9S0Crqh/kBe5hGRegXhlOBlxK4AA5O6tYLvaaHxUrN/kvd6Ew1PzcA= MIME-Version: 1.0 X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-Network-Message-Id: c602ef86-2be4-454c-451c-08d6ac7b7fdf X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Mar 2019 14:59:34.4676 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR02MB5635 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190319_075937_805027_0B2088A4 X-CRM114-Status: GOOD ( 29.52 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: gregkh , Michal Simek , Derek Kiernan , Linux ARM , Linux Kernel Mailing List Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org > -----Original Message----- > From: Arnd Bergmann [mailto:arnd@arndb.de] > Sent: Tuesday 19 March 2019 13:18 > To: Dragan Cvetic > Cc: gregkh ; Michal Simek ; Linux ARM ; > Derek Kiernan ; Linux Kernel Mailing List > Subject: Re: [PATCH 04/12] misc: xilinx_sdfec: Add open, close and ioctl > > On Tue, Mar 19, 2019 at 1:05 PM Dragan Cvetic wrote: > > > > Add char device interface per DT node present and support > > file operations: > > - open(), which keeps only one open per device at a time, > > - close(), which release the open for this device, > > - ioctl(), which provides infrastructure for a specific driver > > control. > > > drivers/misc/xilinx_sdfec.c | 79 ++++++++++++++++++++++++++++++++++++++++ > > include/uapi/misc/xilinx_sdfec.h | 4 ++ > > 2 files changed, 83 insertions(+) > > > > diff --git a/drivers/misc/xilinx_sdfec.c b/drivers/misc/xilinx_sdfec.c > > index a52a5c6..3407de4 100644 > > --- a/drivers/misc/xilinx_sdfec.c > > +++ b/drivers/misc/xilinx_sdfec.c > > @@ -81,8 +81,87 @@ struct xsdfec_dev { > > struct xsdfec_clks clks; > > }; > > > > +static int xsdfec_dev_open(struct inode *iptr, struct file *fptr) > > +{ > > + struct xsdfec_dev *xsdfec; > > + > > + xsdfec = container_of(iptr->i_cdev, struct xsdfec_dev, xsdfec_cdev); > > + if (!xsdfec) > > + return -EAGAIN; > > The result of container_of() will not be NULL here. > Did you mean to check i_cdev? That probably also won't > be NULL, but that check would be more reasonable. Will be either removed fully or changed with i_cdev check > > > + /* Only one open per device at a time */ > > + if (!atomic_dec_and_test(&xsdfec->open_count)) { > > + atomic_inc(&xsdfec->open_count); > > + return -EBUSY; > > + } > > What is that limitation for? Is it worse to open it twice than > to dup() or fork()? > The device can be opened only once. > Note that the test is not really atomic either: if three processes > try to open the file at the same time, it gets decremented from > 1 to -2, so only the second one sees 0 and increments it back > to -1 afterwards... It looks you are right. Will fix this. Thank you for the catch. > > > +static long xsdfec_dev_ioctl(struct file *fptr, unsigned int cmd, > > + unsigned long data) > > +{ > > + struct xsdfec_dev *xsdfec = fptr->private_data; > > + void __user *arg = NULL; > > + int rval = -EINVAL; > > + int err = 0; > > + > > + if (!xsdfec) > > + return rval; > > + > > + if (_IOC_TYPE(cmd) != XSDFEC_MAGIC) { > > + dev_err(xsdfec->dev, "Not a xilinx sdfec ioctl"); > > + return -ENOTTY; > > + } > > remove the error messages here as well. > > > + /* Access check of the argument if present */ > > + if (_IOC_DIR(cmd) & _IOC_READ) > > + err = !access_ok((void *)arg, _IOC_SIZE(cmd)); > > + else if (_IOC_DIR(cmd) & _IOC_WRITE) > > + err = !access_ok((void *)arg, _IOC_SIZE(cmd)); > > This seems odd. Why two separate checks, and why the access_ok() > check when you do a copy_from_user() that contains the same check > later? Accepted, will remove it. > > If you want to get fancy here, you could just copy the data in the main > ioctl handler based on _IOC_SIZE, and pass around normal kernel > pointers from there. Will not be fancy. Thank you for the advice. > > > static const struct file_operations xsdfec_fops = { > > .owner = THIS_MODULE, > > + .open = xsdfec_dev_open, > > + .release = xsdfec_dev_release, > > + .unlocked_ioctl = xsdfec_dev_ioctl, > > }; > > This lacks a .compat_ioctl pointer. This is new for me, I have to investigate more and propose a solution. Thank you for suggestion. > > Arnd _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel