hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/media/dvb-core/dvb_net.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * dvb_net.c
34 *
....@@ -13,18 +14,6 @@
1314 * and Wolfram Stering <wstering@cosy.sbg.ac.at>
1415 *
1516 * ULE Decaps according to RFC 4326.
16
- *
17
- * This program is free software; you can redistribute it and/or
18
- * modify it under the terms of the GNU General Public License
19
- * as published by the Free Software Foundation; either version 2
20
- * of the License, or (at your option) any later version.
21
- *
22
- * This program is distributed in the hope that it will be useful,
23
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
24
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25
- * GNU General Public License for more details.
26
- * To obtain the license, point your browser to
27
- * http://www.gnu.org/copyleft/gpl.html
2817 */
2918
3019 /*
....@@ -558,7 +547,7 @@
558547 h->priv->ule_sndu_type_1 = 1;
559548 h->ts_remain -= 1;
560549 h->from_where += 1;
561
- /* fallthrough */
550
+ fallthrough;
562551 case 0:
563552 h->new_ts = 1;
564553 h->ts += TS_SZ;
....@@ -1575,15 +1564,43 @@
15751564 return dvb_usercopy(file, cmd, arg, dvb_net_do_ioctl);
15761565 }
15771566
1567
+static int locked_dvb_net_open(struct inode *inode, struct file *file)
1568
+{
1569
+ struct dvb_device *dvbdev = file->private_data;
1570
+ struct dvb_net *dvbnet = dvbdev->priv;
1571
+ int ret;
1572
+
1573
+ if (mutex_lock_interruptible(&dvbnet->remove_mutex))
1574
+ return -ERESTARTSYS;
1575
+
1576
+ if (dvbnet->exit) {
1577
+ mutex_unlock(&dvbnet->remove_mutex);
1578
+ return -ENODEV;
1579
+ }
1580
+
1581
+ ret = dvb_generic_open(inode, file);
1582
+
1583
+ mutex_unlock(&dvbnet->remove_mutex);
1584
+
1585
+ return ret;
1586
+}
1587
+
15781588 static int dvb_net_close(struct inode *inode, struct file *file)
15791589 {
15801590 struct dvb_device *dvbdev = file->private_data;
15811591 struct dvb_net *dvbnet = dvbdev->priv;
15821592
1593
+ mutex_lock(&dvbnet->remove_mutex);
1594
+
15831595 dvb_generic_release(inode, file);
15841596
1585
- if(dvbdev->users == 1 && dvbnet->exit == 1)
1597
+ if (dvbdev->users == 1 && dvbnet->exit == 1) {
1598
+ mutex_unlock(&dvbnet->remove_mutex);
15861599 wake_up(&dvbdev->wait_queue);
1600
+ } else {
1601
+ mutex_unlock(&dvbnet->remove_mutex);
1602
+ }
1603
+
15871604 return 0;
15881605 }
15891606
....@@ -1591,7 +1608,7 @@
15911608 static const struct file_operations dvb_net_fops = {
15921609 .owner = THIS_MODULE,
15931610 .unlocked_ioctl = dvb_net_ioctl,
1594
- .open = dvb_generic_open,
1611
+ .open = locked_dvb_net_open,
15951612 .release = dvb_net_close,
15961613 .llseek = noop_llseek,
15971614 };
....@@ -1610,10 +1627,13 @@
16101627 {
16111628 int i;
16121629
1630
+ mutex_lock(&dvbnet->remove_mutex);
16131631 dvbnet->exit = 1;
1632
+ mutex_unlock(&dvbnet->remove_mutex);
1633
+
16141634 if (dvbnet->dvbdev->users < 1)
16151635 wait_event(dvbnet->dvbdev->wait_queue,
1616
- dvbnet->dvbdev->users==1);
1636
+ dvbnet->dvbdev->users == 1);
16171637
16181638 dvb_unregister_device(dvbnet->dvbdev);
16191639
....@@ -1632,6 +1652,7 @@
16321652 int i;
16331653
16341654 mutex_init(&dvbnet->ioctl_mutex);
1655
+ mutex_init(&dvbnet->remove_mutex);
16351656 dvbnet->demux = dmx;
16361657
16371658 for (i=0; i<DVB_NET_DEVICES_MAX; i++)