On 9/27/21 3:30 PM, Dmitrii Shcherbakov wrote: [...]
diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c
[...]
+ +static void +virNodeDeviceCapVPDResourceFormat(virBuffer *buf, virPCIVPDResource *res) +{ + GEnumValue *resRype = NULL; + void (*resFormatFunc)(virBuffer *buf, virPCIVPDResource *res); + + if (G_TYPE_CHECK_INSTANCE_TYPE(res, VIR_TYPE_PCI_VPD_STRING_RESOURCE)) { + resFormatFunc = virNodeDeviceCapVPDStringResourceFormat; + } else if (G_TYPE_CHECK_INSTANCE_TYPE(res, VIR_TYPE_PCI_VPD_KEYWORD_RESOURCE)) { + resFormatFunc = virNodeDeviceCapVPDKeywordResourceFormat; + } else { + /* Unexpected resource type. This should not happen unless the PCI(e) specs + * change and new resource types are introduced into util.virpcivpd. Either way, + * we can only return the control back to the caller here. + */ + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Unexpected VPD resource type encountered during formatting")); + return; + } + virBufferAdjustIndent(buf, 2); + + resRype = virPCIVPDResourceGetResourceType(res); + virBufferEscapeString(buf, "<resource type='%s'>", resRype->value_nick); + /* Format the resource in a type-specific way. */ + resFormatFunc(buf, res);
It's probably irrelevant since this will be mostly rewritten based on Dan's suggestions, but the resFormatFunc() pointer seems like an unnecessary complication - you could just move the if/else construct down to here and call the appropriate function directly.