Skip to content

Commit bf452cb

Browse files
committed
Added check if device is really owned by driver.
1 parent b12d667 commit bf452cb

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

arch/linux_x86_uio/pci_inc.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,18 @@ PciDevice_new_op
233233
{
234234
DEBUG_PRINTF(PDADEBUG_ENTER, "");
235235
extern char uio_sysfs_dir[PDA_STRING_LIMIT];
236-
237-
PciDevice *device = PciDevice_new_int();
236+
PciDevice *device = NULL;
237+
238+
/** Make sure requested device is owend by the driver **/
239+
DEBUG_PRINTF(PDADEBUG_VALUE, "Searching device %s/%s\n", uio_sysfs_dir, uio_sysfs_entry);
240+
char file_path[PDA_STRING_LIMIT];
241+
snprintf(file_path, PDA_STRING_LIMIT, "%s/%s",
242+
uio_sysfs_dir, uio_sysfs_entry);
243+
if (access(file_path, F_OK) != 0 )
244+
{ ERROR_EXIT( ENODEV, exit, "No such device owned by driver!\n" ); }
245+
246+
/** Initialize device **/
247+
device = PciDevice_new_int();
238248
if(device == NULL)
239249
{ ERROR_EXIT( ENODEV, exit, "Memory allocation failed!\n" ); }
240250

0 commit comments

Comments
 (0)