13
13
*/
14
14
15
15
#include <linux/bitfield.h>
16
+ #include <linux/cleanup.h>
16
17
#include <linux/kernel.h>
17
18
#include <linux/sched.h>
18
19
#include <linux/pci.h>
@@ -1460,7 +1461,7 @@ static ssize_t reset_method_store(struct device *dev,
1460
1461
const char * buf , size_t count )
1461
1462
{
1462
1463
struct pci_dev * pdev = to_pci_dev (dev );
1463
- char * options , * tmp_options , * name ;
1464
+ char * tmp_options , * name ;
1464
1465
int m , n ;
1465
1466
u8 reset_methods [PCI_NUM_RESET_METHODS ] = { 0 };
1466
1467
@@ -1475,7 +1476,7 @@ static ssize_t reset_method_store(struct device *dev,
1475
1476
return count ;
1476
1477
}
1477
1478
1478
- options = kstrndup (buf , count , GFP_KERNEL );
1479
+ char * options __free ( kfree ) = kstrndup (buf , count , GFP_KERNEL );
1479
1480
if (!options )
1480
1481
return - ENOMEM ;
1481
1482
@@ -1487,20 +1488,21 @@ static ssize_t reset_method_store(struct device *dev,
1487
1488
1488
1489
name = strim (name );
1489
1490
1491
+ /* Leave previous methods unchanged if input is invalid */
1490
1492
m = reset_method_lookup (name );
1491
1493
if (!m ) {
1492
1494
pci_err (pdev , "Invalid reset method '%s'" , name );
1493
- goto error ;
1495
+ return - EINVAL ;
1494
1496
}
1495
1497
1496
1498
if (pci_reset_fn_methods [m ].reset_fn (pdev , PCI_RESET_PROBE )) {
1497
1499
pci_err (pdev , "Unsupported reset method '%s'" , name );
1498
- goto error ;
1500
+ return - EINVAL ;
1499
1501
}
1500
1502
1501
1503
if (n == PCI_NUM_RESET_METHODS - 1 ) {
1502
1504
pci_err (pdev , "Too many reset methods\n" );
1503
- goto error ;
1505
+ return - EINVAL ;
1504
1506
}
1505
1507
1506
1508
reset_methods [n ++ ] = m ;
@@ -1513,13 +1515,7 @@ static ssize_t reset_method_store(struct device *dev,
1513
1515
reset_methods [0 ] != 1 )
1514
1516
pci_warn (pdev , "Device-specific reset disabled/de-prioritized by user" );
1515
1517
memcpy (pdev -> reset_methods , reset_methods , sizeof (pdev -> reset_methods ));
1516
- kfree (options );
1517
1518
return count ;
1518
-
1519
- error :
1520
- /* Leave previous methods unchanged */
1521
- kfree (options );
1522
- return - EINVAL ;
1523
1519
}
1524
1520
static DEVICE_ATTR_RW (reset_method );
1525
1521
0 commit comments