de1b3800b7
If we want to check error after errp-function call, we need to introduce local_err and then propagate it to errp. Instead, use the ERRP_GUARD() macro, benefits are: 1. No need of explicit error_propagate call 2. No need of explicit local_err variable: use errp directly 3. ERRP_GUARD() leaves errp as is if it's not NULL or &error_fatal, this means that we don't break error_abort (we'll abort on error_set, not on error_propagate) If we want to add some info to errp (by error_prepend() or error_append_hint()), we must use the ERRP_GUARD() macro. Otherwise, this info will not be added when errp == &error_fatal (the program will exit prior to the error_append_hint() or error_prepend() call). No such cases are being fixed here. This commit is generated by command sed -n '/^SD (Secure Card)$/,/^$/{s/^F: //p}' \ MAINTAINERS | \ xargs git ls-files | grep '\.[hc]$' | \ xargs spatch \ --sp-file scripts/coccinelle/errp-guard.cocci \ --macro-file scripts/cocci-macro-file.h \ --in-place --no-show-diff --max-width 80 Reported-by: Kevin Wolf <kwolf@redhat.com> Reported-by: Greg Kurz <groug@kaod.org> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> [Commit message tweaked] Signed-off-by: Markus Armbruster <armbru@redhat.com> Message-Id: <20200707165037.1026246-4-armbru@redhat.com> [ERRP_AUTO_PROPAGATE() renamed to ERRP_GUARD(), and auto-propagated-errp.cocci to errp-guard.cocci. Commit message tweaked again.]
88 lines
2.4 KiB
C
88 lines
2.4 KiB
C
/*
|
|
* SDHCI device on PCI
|
|
*
|
|
* 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, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include "qemu/osdep.h"
|
|
#include "qapi/error.h"
|
|
#include "qemu/module.h"
|
|
#include "hw/qdev-properties.h"
|
|
#include "hw/sd/sdhci.h"
|
|
#include "sdhci-internal.h"
|
|
|
|
static Property sdhci_pci_properties[] = {
|
|
DEFINE_SDHCI_COMMON_PROPERTIES(SDHCIState),
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
};
|
|
|
|
static void sdhci_pci_realize(PCIDevice *dev, Error **errp)
|
|
{
|
|
ERRP_GUARD();
|
|
SDHCIState *s = PCI_SDHCI(dev);
|
|
|
|
sdhci_initfn(s);
|
|
sdhci_common_realize(s, errp);
|
|
if (*errp) {
|
|
return;
|
|
}
|
|
|
|
dev->config[PCI_CLASS_PROG] = 0x01; /* Standard Host supported DMA */
|
|
dev->config[PCI_INTERRUPT_PIN] = 0x01; /* interrupt pin A */
|
|
s->irq = pci_allocate_irq(dev);
|
|
s->dma_as = pci_get_address_space(dev);
|
|
pci_register_bar(dev, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, &s->iomem);
|
|
}
|
|
|
|
static void sdhci_pci_exit(PCIDevice *dev)
|
|
{
|
|
SDHCIState *s = PCI_SDHCI(dev);
|
|
|
|
sdhci_common_unrealize(s);
|
|
sdhci_uninitfn(s);
|
|
}
|
|
|
|
static void sdhci_pci_class_init(ObjectClass *klass, void *data)
|
|
{
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
|
PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
|
|
|
|
k->realize = sdhci_pci_realize;
|
|
k->exit = sdhci_pci_exit;
|
|
k->vendor_id = PCI_VENDOR_ID_REDHAT;
|
|
k->device_id = PCI_DEVICE_ID_REDHAT_SDHCI;
|
|
k->class_id = PCI_CLASS_SYSTEM_SDHCI;
|
|
device_class_set_props(dc, sdhci_pci_properties);
|
|
|
|
sdhci_common_class_init(klass, data);
|
|
}
|
|
|
|
static const TypeInfo sdhci_pci_info = {
|
|
.name = TYPE_PCI_SDHCI,
|
|
.parent = TYPE_PCI_DEVICE,
|
|
.instance_size = sizeof(SDHCIState),
|
|
.class_init = sdhci_pci_class_init,
|
|
.interfaces = (InterfaceInfo[]) {
|
|
{ INTERFACE_CONVENTIONAL_PCI_DEVICE },
|
|
{ },
|
|
},
|
|
};
|
|
|
|
static void sdhci_pci_register_type(void)
|
|
{
|
|
type_register_static(&sdhci_pci_info);
|
|
}
|
|
|
|
type_init(sdhci_pci_register_type)
|