Skip to content

Commit b6e5c46

Browse files
ij-intelkwilczynski
authored andcommitted
PCI/sysfs: Use __free() in reset_method_store()
Use __free() from cleanup.h to handle freeing options in reset_method_store() as it simplifies the code flow. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Ilpo Järvinen <[email protected]> Signed-off-by: Krzysztof Wilczyński <[email protected]>
1 parent 10269d5 commit b6e5c46

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

drivers/pci/pci-sysfs.c

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*/
1414

1515
#include <linux/bitfield.h>
16+
#include <linux/cleanup.h>
1617
#include <linux/kernel.h>
1718
#include <linux/sched.h>
1819
#include <linux/pci.h>
@@ -1460,7 +1461,7 @@ static ssize_t reset_method_store(struct device *dev,
14601461
const char *buf, size_t count)
14611462
{
14621463
struct pci_dev *pdev = to_pci_dev(dev);
1463-
char *options, *tmp_options, *name;
1464+
char *tmp_options, *name;
14641465
int m, n;
14651466
u8 reset_methods[PCI_NUM_RESET_METHODS] = { 0 };
14661467

@@ -1475,7 +1476,7 @@ static ssize_t reset_method_store(struct device *dev,
14751476
return count;
14761477
}
14771478

1478-
options = kstrndup(buf, count, GFP_KERNEL);
1479+
char *options __free(kfree) = kstrndup(buf, count, GFP_KERNEL);
14791480
if (!options)
14801481
return -ENOMEM;
14811482

@@ -1487,20 +1488,21 @@ static ssize_t reset_method_store(struct device *dev,
14871488

14881489
name = strim(name);
14891490

1491+
/* Leave previous methods unchanged if input is invalid */
14901492
m = reset_method_lookup(name);
14911493
if (!m) {
14921494
pci_err(pdev, "Invalid reset method '%s'", name);
1493-
goto error;
1495+
return -EINVAL;
14941496
}
14951497

14961498
if (pci_reset_fn_methods[m].reset_fn(pdev, PCI_RESET_PROBE)) {
14971499
pci_err(pdev, "Unsupported reset method '%s'", name);
1498-
goto error;
1500+
return -EINVAL;
14991501
}
15001502

15011503
if (n == PCI_NUM_RESET_METHODS - 1) {
15021504
pci_err(pdev, "Too many reset methods\n");
1503-
goto error;
1505+
return -EINVAL;
15041506
}
15051507

15061508
reset_methods[n++] = m;
@@ -1513,13 +1515,7 @@ static ssize_t reset_method_store(struct device *dev,
15131515
reset_methods[0] != 1)
15141516
pci_warn(pdev, "Device-specific reset disabled/de-prioritized by user");
15151517
memcpy(pdev->reset_methods, reset_methods, sizeof(pdev->reset_methods));
1516-
kfree(options);
15171518
return count;
1518-
1519-
error:
1520-
/* Leave previous methods unchanged */
1521-
kfree(options);
1522-
return -EINVAL;
15231519
}
15241520
static DEVICE_ATTR_RW(reset_method);
15251521

0 commit comments

Comments
 (0)