diff options
author | Jan Beulich <JBeulich@suse.com> | 2012-09-24 10:55:37 -0400 |
---|---|---|
committer | Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> | 2012-09-25 08:53:27 -0400 |
commit | e6aa70a0d5511296ea3d5fd1f5e2203ff6898107 (patch) | |
tree | 0bffc5bbd72c88d72e9e731be6d942e01ea9f044 /drivers/xen | |
parent | aa387d630cfed1a694a9c8c61fba3877ba8d4f07 (diff) |
xen-pciback: properly clean up after calling pcistub_device_find()
As the function calls pcistub_device_get() before returning non-NULL,
its callers need to take care of calling pcistub_device_put() on
(mostly, but not exclusively) error paths.
Otoh, the function already guarantees that the 'dev' member is non-NULL
upon successful return, so callers do not need to check for this a
second time.
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Diffstat (limited to 'drivers/xen')
-rw-r--r-- | drivers/xen/xen-pciback/pci_stub.c | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/drivers/xen/xen-pciback/pci_stub.c b/drivers/xen/xen-pciback/pci_stub.c index 20e1c42c1c48..acec6faff885 100644 --- a/drivers/xen/xen-pciback/pci_stub.c +++ b/drivers/xen/xen-pciback/pci_stub.c | |||
@@ -681,14 +681,14 @@ static pci_ers_result_t xen_pcibk_slot_reset(struct pci_dev *dev) | |||
681 | dev_err(&dev->dev, DRV_NAME " device is not connected or owned" | 681 | dev_err(&dev->dev, DRV_NAME " device is not connected or owned" |
682 | " by HVM, kill it\n"); | 682 | " by HVM, kill it\n"); |
683 | kill_domain_by_device(psdev); | 683 | kill_domain_by_device(psdev); |
684 | goto release; | 684 | goto end; |
685 | } | 685 | } |
686 | 686 | ||
687 | if (!test_bit(_XEN_PCIB_AERHANDLER, | 687 | if (!test_bit(_XEN_PCIB_AERHANDLER, |
688 | (unsigned long *)&psdev->pdev->sh_info->flags)) { | 688 | (unsigned long *)&psdev->pdev->sh_info->flags)) { |
689 | dev_err(&dev->dev, | 689 | dev_err(&dev->dev, |
690 | "guest with no AER driver should have been killed\n"); | 690 | "guest with no AER driver should have been killed\n"); |
691 | goto release; | 691 | goto end; |
692 | } | 692 | } |
693 | result = common_process(psdev, 1, XEN_PCI_OP_aer_slotreset, result); | 693 | result = common_process(psdev, 1, XEN_PCI_OP_aer_slotreset, result); |
694 | 694 | ||
@@ -698,9 +698,9 @@ static pci_ers_result_t xen_pcibk_slot_reset(struct pci_dev *dev) | |||
698 | "No AER slot_reset service or disconnected!\n"); | 698 | "No AER slot_reset service or disconnected!\n"); |
699 | kill_domain_by_device(psdev); | 699 | kill_domain_by_device(psdev); |
700 | } | 700 | } |
701 | release: | ||
702 | pcistub_device_put(psdev); | ||
703 | end: | 701 | end: |
702 | if (psdev) | ||
703 | pcistub_device_put(psdev); | ||
704 | up_write(&pcistub_sem); | 704 | up_write(&pcistub_sem); |
705 | return result; | 705 | return result; |
706 | 706 | ||
@@ -739,14 +739,14 @@ static pci_ers_result_t xen_pcibk_mmio_enabled(struct pci_dev *dev) | |||
739 | dev_err(&dev->dev, DRV_NAME " device is not connected or owned" | 739 | dev_err(&dev->dev, DRV_NAME " device is not connected or owned" |
740 | " by HVM, kill it\n"); | 740 | " by HVM, kill it\n"); |
741 | kill_domain_by_device(psdev); | 741 | kill_domain_by_device(psdev); |
742 | goto release; | 742 | goto end; |
743 | } | 743 | } |
744 | 744 | ||
745 | if (!test_bit(_XEN_PCIB_AERHANDLER, | 745 | if (!test_bit(_XEN_PCIB_AERHANDLER, |
746 | (unsigned long *)&psdev->pdev->sh_info->flags)) { | 746 | (unsigned long *)&psdev->pdev->sh_info->flags)) { |
747 | dev_err(&dev->dev, | 747 | dev_err(&dev->dev, |
748 | "guest with no AER driver should have been killed\n"); | 748 | "guest with no AER driver should have been killed\n"); |
749 | goto release; | 749 | goto end; |
750 | } | 750 | } |
751 | result = common_process(psdev, 1, XEN_PCI_OP_aer_mmio, result); | 751 | result = common_process(psdev, 1, XEN_PCI_OP_aer_mmio, result); |
752 | 752 | ||
@@ -756,9 +756,9 @@ static pci_ers_result_t xen_pcibk_mmio_enabled(struct pci_dev *dev) | |||
756 | "No AER mmio_enabled service or disconnected!\n"); | 756 | "No AER mmio_enabled service or disconnected!\n"); |
757 | kill_domain_by_device(psdev); | 757 | kill_domain_by_device(psdev); |
758 | } | 758 | } |
759 | release: | ||
760 | pcistub_device_put(psdev); | ||
761 | end: | 759 | end: |
760 | if (psdev) | ||
761 | pcistub_device_put(psdev); | ||
762 | up_write(&pcistub_sem); | 762 | up_write(&pcistub_sem); |
763 | return result; | 763 | return result; |
764 | } | 764 | } |
@@ -797,7 +797,7 @@ static pci_ers_result_t xen_pcibk_error_detected(struct pci_dev *dev, | |||
797 | dev_err(&dev->dev, DRV_NAME " device is not connected or owned" | 797 | dev_err(&dev->dev, DRV_NAME " device is not connected or owned" |
798 | " by HVM, kill it\n"); | 798 | " by HVM, kill it\n"); |
799 | kill_domain_by_device(psdev); | 799 | kill_domain_by_device(psdev); |
800 | goto release; | 800 | goto end; |
801 | } | 801 | } |
802 | 802 | ||
803 | /*Guest owns the device yet no aer handler regiested, kill guest*/ | 803 | /*Guest owns the device yet no aer handler regiested, kill guest*/ |
@@ -805,7 +805,7 @@ static pci_ers_result_t xen_pcibk_error_detected(struct pci_dev *dev, | |||
805 | (unsigned long *)&psdev->pdev->sh_info->flags)) { | 805 | (unsigned long *)&psdev->pdev->sh_info->flags)) { |
806 | dev_dbg(&dev->dev, "guest may have no aer driver, kill it\n"); | 806 | dev_dbg(&dev->dev, "guest may have no aer driver, kill it\n"); |
807 | kill_domain_by_device(psdev); | 807 | kill_domain_by_device(psdev); |
808 | goto release; | 808 | goto end; |
809 | } | 809 | } |
810 | result = common_process(psdev, error, XEN_PCI_OP_aer_detected, result); | 810 | result = common_process(psdev, error, XEN_PCI_OP_aer_detected, result); |
811 | 811 | ||
@@ -815,9 +815,9 @@ static pci_ers_result_t xen_pcibk_error_detected(struct pci_dev *dev, | |||
815 | "No AER error_detected service or disconnected!\n"); | 815 | "No AER error_detected service or disconnected!\n"); |
816 | kill_domain_by_device(psdev); | 816 | kill_domain_by_device(psdev); |
817 | } | 817 | } |
818 | release: | ||
819 | pcistub_device_put(psdev); | ||
820 | end: | 818 | end: |
819 | if (psdev) | ||
820 | pcistub_device_put(psdev); | ||
821 | up_write(&pcistub_sem); | 821 | up_write(&pcistub_sem); |
822 | return result; | 822 | return result; |
823 | } | 823 | } |
@@ -851,7 +851,7 @@ static void xen_pcibk_error_resume(struct pci_dev *dev) | |||
851 | dev_err(&dev->dev, DRV_NAME " device is not connected or owned" | 851 | dev_err(&dev->dev, DRV_NAME " device is not connected or owned" |
852 | " by HVM, kill it\n"); | 852 | " by HVM, kill it\n"); |
853 | kill_domain_by_device(psdev); | 853 | kill_domain_by_device(psdev); |
854 | goto release; | 854 | goto end; |
855 | } | 855 | } |
856 | 856 | ||
857 | if (!test_bit(_XEN_PCIB_AERHANDLER, | 857 | if (!test_bit(_XEN_PCIB_AERHANDLER, |
@@ -859,13 +859,13 @@ static void xen_pcibk_error_resume(struct pci_dev *dev) | |||
859 | dev_err(&dev->dev, | 859 | dev_err(&dev->dev, |
860 | "guest with no AER driver should have been killed\n"); | 860 | "guest with no AER driver should have been killed\n"); |
861 | kill_domain_by_device(psdev); | 861 | kill_domain_by_device(psdev); |
862 | goto release; | 862 | goto end; |
863 | } | 863 | } |
864 | common_process(psdev, 1, XEN_PCI_OP_aer_resume, | 864 | common_process(psdev, 1, XEN_PCI_OP_aer_resume, |
865 | PCI_ERS_RESULT_RECOVERED); | 865 | PCI_ERS_RESULT_RECOVERED); |
866 | release: | ||
867 | pcistub_device_put(psdev); | ||
868 | end: | 866 | end: |
867 | if (psdev) | ||
868 | pcistub_device_put(psdev); | ||
869 | up_write(&pcistub_sem); | 869 | up_write(&pcistub_sem); |
870 | return; | 870 | return; |
871 | } | 871 | } |
@@ -1024,7 +1024,7 @@ static int pcistub_reg_add(int domain, int bus, int slot, int func, int reg, | |||
1024 | struct config_field *field; | 1024 | struct config_field *field; |
1025 | 1025 | ||
1026 | psdev = pcistub_device_find(domain, bus, slot, func); | 1026 | psdev = pcistub_device_find(domain, bus, slot, func); |
1027 | if (!psdev || !psdev->dev) { | 1027 | if (!psdev) { |
1028 | err = -ENODEV; | 1028 | err = -ENODEV; |
1029 | goto out; | 1029 | goto out; |
1030 | } | 1030 | } |
@@ -1048,6 +1048,8 @@ static int pcistub_reg_add(int domain, int bus, int slot, int func, int reg, | |||
1048 | if (err) | 1048 | if (err) |
1049 | kfree(field); | 1049 | kfree(field); |
1050 | out: | 1050 | out: |
1051 | if (psdev) | ||
1052 | pcistub_device_put(psdev); | ||
1051 | return err; | 1053 | return err; |
1052 | } | 1054 | } |
1053 | 1055 | ||
@@ -1152,10 +1154,9 @@ static ssize_t pcistub_irq_handler_switch(struct device_driver *drv, | |||
1152 | 1154 | ||
1153 | err = str_to_slot(buf, &domain, &bus, &slot, &func); | 1155 | err = str_to_slot(buf, &domain, &bus, &slot, &func); |
1154 | if (err) | 1156 | if (err) |
1155 | goto out; | 1157 | return err; |
1156 | 1158 | ||
1157 | psdev = pcistub_device_find(domain, bus, slot, func); | 1159 | psdev = pcistub_device_find(domain, bus, slot, func); |
1158 | |||
1159 | if (!psdev) | 1160 | if (!psdev) |
1160 | goto out; | 1161 | goto out; |
1161 | 1162 | ||
@@ -1171,6 +1172,8 @@ static ssize_t pcistub_irq_handler_switch(struct device_driver *drv, | |||
1171 | if (dev_data->isr_on) | 1172 | if (dev_data->isr_on) |
1172 | dev_data->ack_intr = 1; | 1173 | dev_data->ack_intr = 1; |
1173 | out: | 1174 | out: |
1175 | if (psdev) | ||
1176 | pcistub_device_put(psdev); | ||
1174 | if (!err) | 1177 | if (!err) |
1175 | err = count; | 1178 | err = count; |
1176 | return err; | 1179 | return err; |
@@ -1262,10 +1265,7 @@ static ssize_t permissive_add(struct device_driver *drv, const char *buf, | |||
1262 | err = -ENODEV; | 1265 | err = -ENODEV; |
1263 | goto out; | 1266 | goto out; |
1264 | } | 1267 | } |
1265 | if (!psdev->dev) { | 1268 | |
1266 | err = -ENODEV; | ||
1267 | goto release; | ||
1268 | } | ||
1269 | dev_data = pci_get_drvdata(psdev->dev); | 1269 | dev_data = pci_get_drvdata(psdev->dev); |
1270 | /* the driver data for a device should never be null at this point */ | 1270 | /* the driver data for a device should never be null at this point */ |
1271 | if (!dev_data) { | 1271 | if (!dev_data) { |