/* This function checks if the driver got a valid device from the caller to avoid dereferencing invalid pointers.  */
static bool check_device(struct device *dev)
/* This function checks if the driver got a valid device from the caller to avoid dereferencing invalid pointers.  */
static bool check_device(struct device *dev)
{
	u16 devid;
	if (!dev || !dev->dma_mask)
		return false;
	if (!dev || dev->bus != &pci_bus_type)
		return false;
	devid = get_device_id(dev);
	if (devid > amd_iommu_last_bdf)
		return false;
	if (amd_iommu_rlookup_table[devid] == NULL)
		return false;
	return true;
}