2005-04-17 02:20:36 +04:00
/*
*
2005-08-10 07:27:37 +04:00
* Bluetooth virtual HCI driver
*
2006-07-06 17:45:23 +04:00
* Copyright ( C ) 2000 - 2001 Qualcomm Incorporated
* Copyright ( C ) 2002 - 2003 Maxim Krasnyansky < maxk @ qualcomm . com >
* Copyright ( C ) 2004 - 2006 Marcel Holtmann < marcel @ holtmann . org >
2005-08-10 07:27:37 +04:00
*
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 2 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software
* Foundation , Inc . , 59 Temple Place , Suite 330 , Boston , MA 02111 - 1307 USA
*
2005-04-17 02:20:36 +04:00
*/
# include <linux/module.h>
2013-09-02 21:41:39 +04:00
# include <asm/unaligned.h>
2005-04-17 02:20:36 +04:00
# include <linux/kernel.h>
2005-08-10 07:27:37 +04:00
# include <linux/init.h>
2005-04-17 02:20:36 +04:00
# include <linux/slab.h>
2005-08-10 07:27:37 +04:00
# include <linux/types.h>
# include <linux/errno.h>
# include <linux/sched.h>
2005-04-17 02:20:36 +04:00
# include <linux/poll.h>
# include <linux/skbuff.h>
# include <linux/miscdevice.h>
# include <net/bluetooth/bluetooth.h>
# include <net/bluetooth/hci_core.h>
2014-07-03 03:35:10 +04:00
# define VERSION "1.5"
2005-08-10 07:27:37 +04:00
2011-11-14 14:42:48 +04:00
static bool amp ;
2005-08-10 07:27:37 +04:00
struct vhci_data {
struct hci_dev * hdev ;
wait_queue_head_t read_wait ;
struct sk_buff_head readq ;
2013-09-02 21:41:39 +04:00
2016-04-14 18:32:19 +03:00
struct mutex open_mutex ;
2013-09-02 21:41:39 +04:00
struct delayed_work open_timeout ;
2005-08-10 07:27:37 +04:00
} ;
static int vhci_open_dev ( struct hci_dev * hdev )
2005-04-17 02:20:36 +04:00
{
return 0 ;
}
2005-08-10 07:27:37 +04:00
static int vhci_close_dev ( struct hci_dev * hdev )
2005-04-17 02:20:36 +04:00
{
2012-02-10 00:58:32 +04:00
struct vhci_data * data = hci_get_drvdata ( hdev ) ;
2005-08-10 07:27:37 +04:00
2006-07-06 17:45:23 +04:00
skb_queue_purge ( & data - > readq ) ;
2005-08-10 07:27:37 +04:00
2005-04-17 02:20:36 +04:00
return 0 ;
}
2005-08-10 07:27:37 +04:00
static int vhci_flush ( struct hci_dev * hdev )
2005-04-17 02:20:36 +04:00
{
2012-02-10 00:58:32 +04:00
struct vhci_data * data = hci_get_drvdata ( hdev ) ;
2005-04-17 02:20:36 +04:00
2006-07-06 17:45:23 +04:00
skb_queue_purge ( & data - > readq ) ;
2005-04-17 02:20:36 +04:00
2005-08-10 07:27:37 +04:00
return 0 ;
2005-04-17 02:20:36 +04:00
}
2013-10-11 17:19:18 +04:00
static int vhci_send_frame ( struct hci_dev * hdev , struct sk_buff * skb )
2005-04-17 02:20:36 +04:00
{
2013-10-11 18:01:04 +04:00
struct vhci_data * data = hci_get_drvdata ( hdev ) ;
2005-04-17 02:20:36 +04:00
2015-11-05 09:33:56 +03:00
memcpy ( skb_push ( skb , 1 ) , & hci_skb_pkt_type ( skb ) , 1 ) ;
2006-07-06 17:45:23 +04:00
skb_queue_tail ( & data - > readq , skb ) ;
2005-08-10 07:27:37 +04:00
2006-07-06 17:45:23 +04:00
wake_up_interruptible ( & data - > read_wait ) ;
2013-09-02 21:41:39 +04:00
return 0 ;
}
2016-04-14 18:32:19 +03:00
static int __vhci_create_device ( struct vhci_data * data , __u8 opcode )
2013-09-02 21:41:39 +04:00
{
struct hci_dev * hdev ;
struct sk_buff * skb ;
2014-07-03 03:35:10 +04:00
__u8 dev_type ;
2016-04-14 18:32:19 +03:00
if ( data - > hdev )
return - EBADFD ;
2016-07-05 15:30:14 +03:00
/* bits 0-1 are dev_type (Primary or AMP) */
2014-07-03 03:35:10 +04:00
dev_type = opcode & 0x03 ;
2016-07-05 15:30:14 +03:00
if ( dev_type ! = HCI_PRIMARY & & dev_type ! = HCI_AMP )
2014-07-03 03:35:10 +04:00
return - EINVAL ;
2014-07-04 19:23:35 +04:00
/* bits 2-5 are reserved (must be zero) */
if ( opcode & 0x3c )
2014-07-03 03:35:10 +04:00
return - EINVAL ;
2013-09-02 21:41:39 +04:00
skb = bt_skb_alloc ( 4 , GFP_KERNEL ) ;
if ( ! skb )
return - ENOMEM ;
hdev = hci_alloc_dev ( ) ;
if ( ! hdev ) {
kfree_skb ( skb ) ;
return - ENOMEM ;
}
data - > hdev = hdev ;
hdev - > bus = HCI_VIRTUAL ;
hdev - > dev_type = dev_type ;
hci_set_drvdata ( hdev , data ) ;
hdev - > open = vhci_open_dev ;
hdev - > close = vhci_close_dev ;
hdev - > flush = vhci_flush ;
hdev - > send = vhci_send_frame ;
2005-04-17 02:20:36 +04:00
2014-07-04 19:23:35 +04:00
/* bit 6 is for external configuration */
if ( opcode & 0x40 )
set_bit ( HCI_QUIRK_EXTERNAL_CONFIG , & hdev - > quirks ) ;
2014-07-03 03:35:10 +04:00
/* bit 7 is for raw device */
if ( opcode & 0x80 )
set_bit ( HCI_QUIRK_RAW_DEVICE , & hdev - > quirks ) ;
2013-09-02 21:41:39 +04:00
if ( hci_register_dev ( hdev ) < 0 ) {
BT_ERR ( " Can't register HCI device " ) ;
hci_free_dev ( hdev ) ;
data - > hdev = NULL ;
kfree_skb ( skb ) ;
return - EBUSY ;
}
2015-11-05 09:33:56 +03:00
hci_skb_pkt_type ( skb ) = HCI_VENDOR_PKT ;
2013-09-02 21:41:39 +04:00
networking: add and use skb_put_u8()
Joe and Bjørn suggested that it'd be nicer to not have the
cast in the fairly common case of doing
*(u8 *)skb_put(skb, 1) = c;
Add skb_put_u8() for this case, and use it across the code,
using the following spatch:
@@
expression SKB, C, S;
typedef u8;
identifier fn = {skb_put};
fresh identifier fn2 = fn ## "_u8";
@@
- *(u8 *)fn(SKB, S) = C;
+ fn2(SKB, C);
Note that due to the "S", the spatch isn't perfect, it should
have checked that S is 1, but there's also places that use a
sizeof expression like sizeof(var) or sizeof(u8) etc. Turns
out that nobody ever did something like
*(u8 *)skb_put(skb, 2) = c;
which would be wrong anyway since the second byte wouldn't be
initialized.
Suggested-by: Joe Perches <joe@perches.com>
Suggested-by: Bjørn Mork <bjorn@mork.no>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-06-16 15:29:24 +03:00
skb_put_u8 ( skb , 0xff ) ;
skb_put_u8 ( skb , opcode ) ;
2013-09-02 21:41:39 +04:00
put_unaligned_le16 ( hdev - > id , skb_put ( skb , 2 ) ) ;
skb_queue_tail ( & data - > readq , skb ) ;
wake_up_interruptible ( & data - > read_wait ) ;
2005-04-17 02:20:36 +04:00
return 0 ;
}
2016-04-14 18:32:19 +03:00
static int vhci_create_device ( struct vhci_data * data , __u8 opcode )
{
int err ;
mutex_lock ( & data - > open_mutex ) ;
err = __vhci_create_device ( data , opcode ) ;
mutex_unlock ( & data - > open_mutex ) ;
return err ;
}
2006-07-06 17:45:23 +04:00
static inline ssize_t vhci_get_user ( struct vhci_data * data ,
2014-08-23 19:28:14 +04:00
struct iov_iter * from )
2005-04-17 02:20:36 +04:00
{
2014-08-23 19:28:14 +04:00
size_t len = iov_iter_count ( from ) ;
2005-04-17 02:20:36 +04:00
struct sk_buff * skb ;
2014-07-03 03:35:10 +04:00
__u8 pkt_type , opcode ;
2013-09-02 21:41:39 +04:00
int ret ;
2005-04-17 02:20:36 +04:00
2013-12-29 09:57:14 +04:00
if ( len < 2 | | len > HCI_MAX_FRAME_SIZE )
2005-04-17 02:20:36 +04:00
return - EINVAL ;
2013-12-29 09:57:14 +04:00
skb = bt_skb_alloc ( len , GFP_KERNEL ) ;
2005-08-10 07:27:37 +04:00
if ( ! skb )
2005-04-17 02:20:36 +04:00
return - ENOMEM ;
2005-08-10 07:27:37 +04:00
2016-11-02 05:09:04 +03:00
if ( ! copy_from_iter_full ( skb_put ( skb , len ) , len , from ) ) {
2014-08-23 19:28:14 +04:00
kfree_skb ( skb ) ;
return - EFAULT ;
2005-04-17 02:20:36 +04:00
}
2013-09-02 21:41:39 +04:00
pkt_type = * ( ( __u8 * ) skb - > data ) ;
2005-04-17 02:20:36 +04:00
skb_pull ( skb , 1 ) ;
2013-09-02 21:41:39 +04:00
switch ( pkt_type ) {
case HCI_EVENT_PKT :
case HCI_ACLDATA_PKT :
case HCI_SCODATA_PKT :
if ( ! data - > hdev ) {
kfree_skb ( skb ) ;
return - ENODEV ;
}
2015-11-05 09:33:56 +03:00
hci_skb_pkt_type ( skb ) = pkt_type ;
2013-09-02 21:41:39 +04:00
2013-10-11 03:52:43 +04:00
ret = hci_recv_frame ( data - > hdev , skb ) ;
2013-09-02 21:41:39 +04:00
break ;
case HCI_VENDOR_PKT :
2016-03-19 13:05:18 +03:00
cancel_delayed_work_sync ( & data - > open_timeout ) ;
2014-07-03 03:35:10 +04:00
opcode = * ( ( __u8 * ) skb - > data ) ;
2013-09-02 21:41:39 +04:00
skb_pull ( skb , 1 ) ;
if ( skb - > len > 0 ) {
kfree_skb ( skb ) ;
return - EINVAL ;
}
kfree_skb ( skb ) ;
2014-07-03 03:35:10 +04:00
ret = vhci_create_device ( data , opcode ) ;
2013-09-02 21:41:39 +04:00
break ;
default :
kfree_skb ( skb ) ;
return - EINVAL ;
}
2013-12-29 09:57:14 +04:00
return ( ret < 0 ) ? ret : len ;
2005-04-17 02:20:36 +04:00
}
2006-07-06 17:45:23 +04:00
static inline ssize_t vhci_put_user ( struct vhci_data * data ,
2013-09-02 21:41:39 +04:00
struct sk_buff * skb ,
char __user * buf , int count )
2005-04-17 02:20:36 +04:00
{
char __user * ptr = buf ;
2013-09-02 21:41:39 +04:00
int len ;
2005-08-10 07:27:37 +04:00
len = min_t ( unsigned int , skb - > len , count ) ;
2005-04-17 02:20:36 +04:00
if ( copy_to_user ( ptr , skb - > data , len ) )
return - EFAULT ;
2005-08-10 07:27:37 +04:00
2013-09-02 21:41:39 +04:00
if ( ! data - > hdev )
return len ;
2005-04-17 02:20:36 +04:00
2006-07-06 17:45:23 +04:00
data - > hdev - > stat . byte_tx + = len ;
2005-08-10 07:27:37 +04:00
2015-11-05 09:33:56 +03:00
switch ( hci_skb_pkt_type ( skb ) ) {
2005-08-10 07:30:28 +04:00
case HCI_COMMAND_PKT :
2006-07-06 17:45:23 +04:00
data - > hdev - > stat . cmd_tx + + ;
2005-08-10 07:30:28 +04:00
break ;
case HCI_ACLDATA_PKT :
2006-07-06 17:45:23 +04:00
data - > hdev - > stat . acl_tx + + ;
2005-08-10 07:30:28 +04:00
break ;
case HCI_SCODATA_PKT :
2010-05-01 23:15:34 +04:00
data - > hdev - > stat . sco_tx + + ;
2005-08-10 07:30:28 +04:00
break ;
2012-09-07 19:24:47 +04:00
}
2005-04-17 02:20:36 +04:00
2013-09-02 21:41:39 +04:00
return len ;
2005-04-17 02:20:36 +04:00
}
2006-07-06 17:45:23 +04:00
static ssize_t vhci_read ( struct file * file ,
2013-09-02 21:41:39 +04:00
char __user * buf , size_t count , loff_t * pos )
2005-04-17 02:20:36 +04:00
{
2006-07-06 17:45:23 +04:00
struct vhci_data * data = file - > private_data ;
2005-04-17 02:20:36 +04:00
struct sk_buff * skb ;
ssize_t ret = 0 ;
while ( count ) {
2006-07-06 17:45:23 +04:00
skb = skb_dequeue ( & data - > readq ) ;
2009-06-08 16:13:57 +04:00
if ( skb ) {
ret = vhci_put_user ( data , skb , buf , count ) ;
if ( ret < 0 )
skb_queue_head ( & data - > readq , skb ) ;
else
kfree_skb ( skb ) ;
break ;
2005-04-17 02:20:36 +04:00
}
2009-06-08 16:13:57 +04:00
if ( file - > f_flags & O_NONBLOCK ) {
ret = - EAGAIN ;
break ;
}
2005-04-17 02:20:36 +04:00
2009-06-08 16:13:57 +04:00
ret = wait_event_interruptible ( data - > read_wait ,
2013-09-02 21:41:39 +04:00
! skb_queue_empty ( & data - > readq ) ) ;
2009-06-08 16:13:57 +04:00
if ( ret < 0 )
break ;
2005-04-17 02:20:36 +04:00
}
return ret ;
}
2014-08-23 19:28:14 +04:00
static ssize_t vhci_write ( struct kiocb * iocb , struct iov_iter * from )
2005-04-17 02:20:36 +04:00
{
2013-12-29 09:57:14 +04:00
struct file * file = iocb - > ki_filp ;
2006-07-06 17:45:23 +04:00
struct vhci_data * data = file - > private_data ;
2005-04-17 02:20:36 +04:00
2014-08-23 19:28:14 +04:00
return vhci_get_user ( data , from ) ;
2005-04-17 02:20:36 +04:00
}
2017-07-03 13:39:46 +03:00
static __poll_t vhci_poll ( struct file * file , poll_table * wait )
2005-04-17 02:20:36 +04:00
{
2006-07-06 17:45:23 +04:00
struct vhci_data * data = file - > private_data ;
2005-04-17 02:20:36 +04:00
2006-07-06 17:45:23 +04:00
poll_wait ( file , & data - > read_wait , wait ) ;
2005-04-17 02:20:36 +04:00
2006-07-06 17:45:23 +04:00
if ( ! skb_queue_empty ( & data - > readq ) )
2018-02-12 01:34:03 +03:00
return EPOLLIN | EPOLLRDNORM ;
2005-08-10 07:27:37 +04:00
2018-02-12 01:34:03 +03:00
return EPOLLOUT | EPOLLWRNORM ;
2005-08-10 07:27:37 +04:00
}
2013-09-02 21:41:39 +04:00
static void vhci_open_timeout ( struct work_struct * work )
{
struct vhci_data * data = container_of ( work , struct vhci_data ,
open_timeout . work ) ;
2016-07-05 15:30:14 +03:00
vhci_create_device ( data , amp ? HCI_AMP : HCI_PRIMARY ) ;
2013-09-02 21:41:39 +04:00
}
2005-08-10 07:27:37 +04:00
static int vhci_open ( struct inode * inode , struct file * file )
2005-04-17 02:20:36 +04:00
{
2006-07-06 17:45:23 +04:00
struct vhci_data * data ;
2005-04-17 02:20:36 +04:00
2006-07-06 17:45:23 +04:00
data = kzalloc ( sizeof ( struct vhci_data ) , GFP_KERNEL ) ;
if ( ! data )
2005-04-17 02:20:36 +04:00
return - ENOMEM ;
2006-07-06 17:45:23 +04:00
skb_queue_head_init ( & data - > readq ) ;
init_waitqueue_head ( & data - > read_wait ) ;
2005-04-17 02:20:36 +04:00
2016-04-14 18:32:19 +03:00
mutex_init ( & data - > open_mutex ) ;
2013-09-02 21:41:39 +04:00
INIT_DELAYED_WORK ( & data - > open_timeout , vhci_open_timeout ) ;
2005-04-17 02:20:36 +04:00
2006-07-06 17:45:23 +04:00
file - > private_data = data ;
2012-03-28 13:48:42 +04:00
nonseekable_open ( inode , file ) ;
2005-08-10 07:27:37 +04:00
2013-09-02 21:41:39 +04:00
schedule_delayed_work ( & data - > open_timeout , msecs_to_jiffies ( 1000 ) ) ;
2012-03-28 13:48:42 +04:00
return 0 ;
2005-04-17 02:20:36 +04:00
}
2005-08-10 07:27:37 +04:00
static int vhci_release ( struct inode * inode , struct file * file )
2005-04-17 02:20:36 +04:00
{
2006-07-06 17:45:23 +04:00
struct vhci_data * data = file - > private_data ;
2016-03-19 13:05:18 +03:00
struct hci_dev * hdev ;
2005-04-17 02:20:36 +04:00
2013-09-02 21:41:39 +04:00
cancel_delayed_work_sync ( & data - > open_timeout ) ;
2016-03-19 13:05:18 +03:00
hdev = data - > hdev ;
2013-09-02 21:41:39 +04:00
if ( hdev ) {
hci_unregister_dev ( hdev ) ;
hci_free_dev ( hdev ) ;
}
2005-04-17 02:20:36 +04:00
Bluetooth: vhci: purge unhandled skbs
The write handler allocates skbs and queues them into data->readq.
Read side should read them, if there is any. If there is none, skbs
should be dropped by hdev->flush. But this happens only if the device
is HCI_UP, i.e. hdev->power_on work was triggered already. When it was
not, skbs stay allocated in the queue when /dev/vhci is closed. So
purge the queue in ->release.
Program to reproduce:
#include <err.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/uio.h>
int main()
{
char buf[] = { 0xff, 0 };
struct iovec iov = {
.iov_base = buf,
.iov_len = sizeof(buf),
};
int fd;
while (1) {
fd = open("/dev/vhci", O_RDWR);
if (fd < 0)
err(1, "open");
usleep(50);
if (writev(fd, &iov, 1) < 0)
err(1, "writev");
usleep(50);
close(fd);
}
return 0;
}
Result:
kmemleak: 4609 new suspected memory leaks
unreferenced object 0xffff88059f4d5440 (size 232):
comm "vhci", pid 1084, jiffies 4294912542 (age 37569.296s)
hex dump (first 32 bytes):
20 f0 23 87 05 88 ff ff 20 f0 23 87 05 88 ff ff .#..... .#.....
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
backtrace:
...
[<ffffffff81ece010>] __alloc_skb+0x0/0x5a0
[<ffffffffa021886c>] vhci_create_device+0x5c/0x580 [hci_vhci]
[<ffffffffa0219436>] vhci_write+0x306/0x4c8 [hci_vhci]
Fixes: 23424c0d31 (Bluetooth: Add support creating virtual AMP controllers)
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Cc: stable 3.13+ <stable@vger.kernel.org>
2016-03-19 13:49:43 +03:00
skb_queue_purge ( & data - > readq ) ;
2005-04-17 02:20:36 +04:00
file - > private_data = NULL ;
2012-01-07 18:47:14 +04:00
kfree ( data ) ;
2005-08-10 07:27:37 +04:00
return 0 ;
}
2007-02-12 11:55:32 +03:00
static const struct file_operations vhci_fops = {
2009-12-03 20:07:28 +03:00
. owner = THIS_MODULE ,
2005-08-10 07:27:37 +04:00
. read = vhci_read ,
2014-08-23 19:28:14 +04:00
. write_iter = vhci_write ,
2005-08-10 07:27:37 +04:00
. poll = vhci_poll ,
. open = vhci_open ,
. release = vhci_release ,
llseek: automatically add .llseek fop
All file_operations should get a .llseek operation so we can make
nonseekable_open the default for future file operations without a
.llseek pointer.
The three cases that we can automatically detect are no_llseek, seq_lseek
and default_llseek. For cases where we can we can automatically prove that
the file offset is always ignored, we use noop_llseek, which maintains
the current behavior of not returning an error from a seek.
New drivers should normally not use noop_llseek but instead use no_llseek
and call nonseekable_open at open time. Existing drivers can be converted
to do the same when the maintainer knows for certain that no user code
relies on calling seek on the device file.
The generated code is often incorrectly indented and right now contains
comments that clarify for each added line why a specific variant was
chosen. In the version that gets submitted upstream, the comments will
be gone and I will manually fix the indentation, because there does not
seem to be a way to do that using coccinelle.
Some amount of new code is currently sitting in linux-next that should get
the same modifications, which I will do at the end of the merge window.
Many thanks to Julia Lawall for helping me learn to write a semantic
patch that does all this.
===== begin semantic patch =====
// This adds an llseek= method to all file operations,
// as a preparation for making no_llseek the default.
//
// The rules are
// - use no_llseek explicitly if we do nonseekable_open
// - use seq_lseek for sequential files
// - use default_llseek if we know we access f_pos
// - use noop_llseek if we know we don't access f_pos,
// but we still want to allow users to call lseek
//
@ open1 exists @
identifier nested_open;
@@
nested_open(...)
{
<+...
nonseekable_open(...)
...+>
}
@ open exists@
identifier open_f;
identifier i, f;
identifier open1.nested_open;
@@
int open_f(struct inode *i, struct file *f)
{
<+...
(
nonseekable_open(...)
|
nested_open(...)
)
...+>
}
@ read disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ read_no_fpos disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
... when != off
}
@ write @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ write_no_fpos @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
... when != off
}
@ fops0 @
identifier fops;
@@
struct file_operations fops = {
...
};
@ has_llseek depends on fops0 @
identifier fops0.fops;
identifier llseek_f;
@@
struct file_operations fops = {
...
.llseek = llseek_f,
...
};
@ has_read depends on fops0 @
identifier fops0.fops;
identifier read_f;
@@
struct file_operations fops = {
...
.read = read_f,
...
};
@ has_write depends on fops0 @
identifier fops0.fops;
identifier write_f;
@@
struct file_operations fops = {
...
.write = write_f,
...
};
@ has_open depends on fops0 @
identifier fops0.fops;
identifier open_f;
@@
struct file_operations fops = {
...
.open = open_f,
...
};
// use no_llseek if we call nonseekable_open
////////////////////////////////////////////
@ nonseekable1 depends on !has_llseek && has_open @
identifier fops0.fops;
identifier nso ~= "nonseekable_open";
@@
struct file_operations fops = {
... .open = nso, ...
+.llseek = no_llseek, /* nonseekable */
};
@ nonseekable2 depends on !has_llseek @
identifier fops0.fops;
identifier open.open_f;
@@
struct file_operations fops = {
... .open = open_f, ...
+.llseek = no_llseek, /* open uses nonseekable */
};
// use seq_lseek for sequential files
/////////////////////////////////////
@ seq depends on !has_llseek @
identifier fops0.fops;
identifier sr ~= "seq_read";
@@
struct file_operations fops = {
... .read = sr, ...
+.llseek = seq_lseek, /* we have seq_read */
};
// use default_llseek if there is a readdir
///////////////////////////////////////////
@ fops1 depends on !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier readdir_e;
@@
// any other fop is used that changes pos
struct file_operations fops = {
... .readdir = readdir_e, ...
+.llseek = default_llseek, /* readdir is present */
};
// use default_llseek if at least one of read/write touches f_pos
/////////////////////////////////////////////////////////////////
@ fops2 depends on !fops1 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read.read_f;
@@
// read fops use offset
struct file_operations fops = {
... .read = read_f, ...
+.llseek = default_llseek, /* read accesses f_pos */
};
@ fops3 depends on !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write.write_f;
@@
// write fops use offset
struct file_operations fops = {
... .write = write_f, ...
+ .llseek = default_llseek, /* write accesses f_pos */
};
// Use noop_llseek if neither read nor write accesses f_pos
///////////////////////////////////////////////////////////
@ fops4 depends on !fops1 && !fops2 && !fops3 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
identifier write_no_fpos.write_f;
@@
// write fops use offset
struct file_operations fops = {
...
.write = write_f,
.read = read_f,
...
+.llseek = noop_llseek, /* read and write both use no f_pos */
};
@ depends on has_write && !has_read && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write_no_fpos.write_f;
@@
struct file_operations fops = {
... .write = write_f, ...
+.llseek = noop_llseek, /* write uses no f_pos */
};
@ depends on has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
@@
struct file_operations fops = {
... .read = read_f, ...
+.llseek = noop_llseek, /* read uses no f_pos */
};
@ depends on !has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
@@
struct file_operations fops = {
...
+.llseek = noop_llseek, /* no read or write fn */
};
===== End semantic patch =====
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Cc: Julia Lawall <julia@diku.dk>
Cc: Christoph Hellwig <hch@infradead.org>
2010-08-15 20:52:59 +04:00
. llseek = no_llseek ,
2005-04-17 02:20:36 +04:00
} ;
2015-06-02 13:50:15 +03:00
static struct miscdevice vhci_miscdev = {
2009-06-07 20:09:57 +04:00
. name = " vhci " ,
. fops = & vhci_fops ,
2014-02-18 09:19:26 +04:00
. minor = VHCI_MINOR ,
2005-04-17 02:20:36 +04:00
} ;
2016-08-25 20:00:50 +03:00
module_misc_device ( vhci_miscdev ) ;
2005-08-10 07:27:37 +04:00
2011-11-14 14:42:48 +04:00
module_param ( amp , bool , 0644 ) ;
MODULE_PARM_DESC ( amp , " Create AMP controller device " ) ;
2008-08-18 15:23:53 +04:00
MODULE_AUTHOR ( " Marcel Holtmann <marcel@holtmann.org> " ) ;
2005-08-10 07:27:37 +04:00
MODULE_DESCRIPTION ( " Bluetooth virtual HCI driver ver " VERSION ) ;
MODULE_VERSION ( VERSION ) ;
MODULE_LICENSE ( " GPL " ) ;
2013-08-27 09:02:38 +04:00
MODULE_ALIAS ( " devname:vhci " ) ;
2014-02-18 09:19:26 +04:00
MODULE_ALIAS_MISCDEV ( VHCI_MINOR ) ;