Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp7885014pxb; Fri, 19 Feb 2021 01:40:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJzRdANmH6cmhjfmzw9Ptv4NNaTI4EqsbQy+mfy4Si1mcalFKDH3E3WttTCyrNMDOwQAYVmv X-Received: by 2002:a17:906:4cd3:: with SMTP id q19mr7751052ejt.78.1613727604509; Fri, 19 Feb 2021 01:40:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613727604; cv=none; d=google.com; s=arc-20160816; b=mnzjmaiHbZah1faL+7m8CMRVbmgNIyooIwWaEy8DJCU/IC7mSOsQsxaE9iy2ydFjIE MeA6oCn+XGPd8M3lkl6ySJMtutuFv1vVEOmU9TBRUm73ypmvwxlcC9G08M6x2wmGko5L VLbDzDBwoitQajpbr3g/8nJCbaDJ2r8cEH7Z8J9HTULyTptIVKmUvBJLtpvEf4MY4Dwg y12OaAz2cpfItv300/2p2GZ5NeljwTYbhPTxCIdHqrraIiNkUkRxuRV7o7oWkMMalJhO 9p9Yr8tZmPldfFOLH+9fsndvn+4ZqlETcQKhUc9VMEGpcPnv1Ayo/Q6FI3B/o0UPkMox aErw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:accept-language:in-reply-to:references:message-id:date :thread-index:thread-topic:subject:cc:to:from; bh=09kzfwBfEvnhxLlWihIQq958yktm93Lk1NjYFDEDlHU=; b=avRtrqJC0NX/z93CdftyumE/kZ5r1QWrOL2XQP4RmFp97ENweELbz8WqYQ7qawmZAM 6meRNcF4inVRDrPKLWiweE3Gh6P1Ovys5otYXma2ZIujvEsFw/Xwz1p9lWDqdAHoy2+L AaPZU6IBYvDx05vdLlUv/kyHjWFR+fXjqBSBydIB1KhYO/i96kzDEIJT9oAZvdSOfuPk 4CeiLVmQllp5kBB8czLQiBuVuIgPze6dYAmb2SGmgwebN0wXSGKJwy535Py9ZSAvBJ7k aWakZUf/KFs70SIJzPA28cvyqdZhxcofEm18d21dGrJmKQTccQDEVtgfRNoYSy1XgVh+ N5+g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q17si5296382ejd.397.2021.02.19.01.39.39; Fri, 19 Feb 2021 01:40:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229947AbhBSJid convert rfc822-to-8bit (ORCPT + 99 others); Fri, 19 Feb 2021 04:38:33 -0500 Received: from eu-smtp-delivery-151.mimecast.com ([207.82.80.151]:54322 "EHLO eu-smtp-delivery-151.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229555AbhBSJi2 (ORCPT ); Fri, 19 Feb 2021 04:38:28 -0500 Received: from AcuMS.aculab.com (156.67.243.126 [156.67.243.126]) (Using TLS) by relay.mimecast.com with ESMTP id uk-mta-212-TcjZYt7SNVyQ4wzD2XdMvA-1; Fri, 19 Feb 2021 09:36:48 +0000 X-MC-Unique: TcjZYt7SNVyQ4wzD2XdMvA-1 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:43c:695e:880f:8750) by AcuMS.aculab.com (fd9f:af1c:a25b:0:43c:695e:880f:8750) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Fri, 19 Feb 2021 09:36:48 +0000 Received: from AcuMS.Aculab.com ([fe80::43c:695e:880f:8750]) by AcuMS.aculab.com ([fe80::43c:695e:880f:8750%12]) with mapi id 15.00.1347.000; Fri, 19 Feb 2021 09:36:48 +0000 From: David Laight To: 'Dan Carpenter' CC: 'Ian Abbott' , Greg KH , Atul Gopinathan , "devel@driverdev.osuosl.org" , "linux-kernel@vger.kernel.org" Subject: RE: [PATCH] staging: comedi: cast to (unsigned int *) Thread-Topic: [PATCH] staging: comedi: cast to (unsigned int *) Thread-Index: AQHXBghs86N7pNMIM0eNnSVMq+7RAqpfL5hQgAAG6ICAAAGSoA== Date: Fri, 19 Feb 2021 09:36:48 +0000 Message-ID: References: <20210217165907.9777-1-atulgopinathan@gmail.com> <20210217181000.GB10124@atulu-ubuntu> <3cfef23d-8d4a-205c-61e8-cbe8c9a0c0f4@mev.co.uk> <21a953261eb44e7ba302cfe74d8efa2d@AcuMS.aculab.com> <20210219092621.GU2087@kadam> In-Reply-To: <20210219092621.GU2087@kadam> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=C51A453 smtp.mailfrom=david.laight@aculab.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dan Carpenter > Sent: 19 February 2021 09:26 > > On Fri, Feb 19, 2021 at 09:03:59AM +0000, David Laight wrote: > > > It's kind of moot anyway because the patch is outdated. But the reason > > > for the ___force is that the same `struct comedi_cmd` is used in both > > > user and kernel contexts. In user contexts, the `chanlist` member > > > points to user memory and in kernel contexts it points to kernel memory > > > (copied from userspace). > > > > Can't you use a union of the user and kernel pointers? > > (Possibly even anonymous?) > > Although, ideally, keeping them in separate fields is better. > > 8 bytes for a pointer isn't going make a fat lot of difference. > > > > Creating a union is worse than adding casts. With the casts, at least > you know that you're doing something dangerous. It's good that it looks > scary because it is scary. > > Keeping them in separate fields is a good idea, but this is part of the > user space API so it's not possible. > > The best we can do is adding some more comments so people know why we > are doing the scary casts. Another option is to use a longer structure in the kernel with the kernel pointer in the 'extension'. So you could have: struct kernel_foo { struct foo; void *kernel_pointer; }; David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)