diff mbox

[1/3] pci-assign: use monitor_handle_fd_param

Message ID 1348523754-6897-2-git-send-email-lcapitulino@redhat.com
State New
Headers show

Commit Message

Luiz Capitulino Sept. 24, 2012, 9:55 p.m. UTC
From: Paolo Bonzini <pbonzini@redhat.com>

There is no need to open-code the choice between a file descriptor
number or a named one.  Just use monitor_handle_fd_param, which
also takes care of printing the error message.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 hw/kvm/pci-assign.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

Comments

Markus Armbruster Sept. 25, 2012, 11:03 a.m. UTC | #1
Luiz Capitulino <lcapitulino@redhat.com> writes:

> From: Paolo Bonzini <pbonzini@redhat.com>
>
> There is no need to open-code the choice between a file descriptor
> number or a named one.  Just use monitor_handle_fd_param, which
> also takes care of printing the error message.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
> ---
>  hw/kvm/pci-assign.c | 12 +++---------
>  1 file changed, 3 insertions(+), 9 deletions(-)
>
> diff --git a/hw/kvm/pci-assign.c b/hw/kvm/pci-assign.c
> index 05b93d9..7a0998c 100644
> --- a/hw/kvm/pci-assign.c
> +++ b/hw/kvm/pci-assign.c
> @@ -579,15 +579,9 @@ static int get_real_device(AssignedDevice *pci_dev, uint16_t r_seg,
>      snprintf(name, sizeof(name), "%sconfig", dir);
>  
>      if (pci_dev->configfd_name && *pci_dev->configfd_name) {
> -        if (qemu_isdigit(pci_dev->configfd_name[0])) {
> -            dev->config_fd = strtol(pci_dev->configfd_name, NULL, 0);
> -        } else {
> -            dev->config_fd = monitor_get_fd(cur_mon, pci_dev->configfd_name);
> -            if (dev->config_fd < 0) {
> -                error_report("%s: (%s) unkown", __func__,
> -                             pci_dev->configfd_name);
> -                return 1;
> -            }
> +        dev->config_fd = monitor_handle_fd_param(cur_mon, pci_dev->configfd_name);
> +        if (dev->config_fd < 0) {
> +            return 1;
>          }
>      } else {
>          dev->config_fd = open(name, O_RDWR);

Silent change: no longer accepts file descriptors in octal and hex.

Silent fix: now rejects junk after numeric file descriptor.  

Both are fine with me, but perhaps worth mentioning in the commit
message.
Markus Armbruster Sept. 26, 2012, 7:54 a.m. UTC | #2
Markus Armbruster <armbru@redhat.com> writes:

> Luiz Capitulino <lcapitulino@redhat.com> writes:
>
>> From: Paolo Bonzini <pbonzini@redhat.com>
>>
>> There is no need to open-code the choice between a file descriptor
>> number or a named one.  Just use monitor_handle_fd_param, which
>> also takes care of printing the error message.
>>
>> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
>> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
>> ---
>>  hw/kvm/pci-assign.c | 12 +++---------
>>  1 file changed, 3 insertions(+), 9 deletions(-)
>>
>> diff --git a/hw/kvm/pci-assign.c b/hw/kvm/pci-assign.c
>> index 05b93d9..7a0998c 100644
>> --- a/hw/kvm/pci-assign.c
>> +++ b/hw/kvm/pci-assign.c
>> @@ -579,15 +579,9 @@ static int get_real_device(AssignedDevice *pci_dev, uint16_t r_seg,
>>      snprintf(name, sizeof(name), "%sconfig", dir);
>>  
>>      if (pci_dev->configfd_name && *pci_dev->configfd_name) {
>> -        if (qemu_isdigit(pci_dev->configfd_name[0])) {
>> -            dev->config_fd = strtol(pci_dev->configfd_name, NULL, 0);
>> -        } else {
>> -            dev->config_fd = monitor_get_fd(cur_mon, pci_dev->configfd_name);
>> -            if (dev->config_fd < 0) {
>> -                error_report("%s: (%s) unkown", __func__,
>> -                             pci_dev->configfd_name);
>> -                return 1;
>> -            }
>> +        dev->config_fd = monitor_handle_fd_param(cur_mon, pci_dev->configfd_name);
>> +        if (dev->config_fd < 0) {
>> +            return 1;
>>          }
>>      } else {
>>          dev->config_fd = open(name, O_RDWR);
>
> Silent change: no longer accepts file descriptors in octal and hex.
>
> Silent fix: now rejects junk after numeric file descriptor.  
>
> Both are fine with me, but perhaps worth mentioning in the commit
> message.

One more thought: this parses qdev "kvm-pci-assign" property "configfd".
A real "fd" property (qdev_prop_fd & friends) would be cleaner, but as
long as this is the only instance, it's not worth the trouble.
diff mbox

Patch

diff --git a/hw/kvm/pci-assign.c b/hw/kvm/pci-assign.c
index 05b93d9..7a0998c 100644
--- a/hw/kvm/pci-assign.c
+++ b/hw/kvm/pci-assign.c
@@ -579,15 +579,9 @@  static int get_real_device(AssignedDevice *pci_dev, uint16_t r_seg,
     snprintf(name, sizeof(name), "%sconfig", dir);
 
     if (pci_dev->configfd_name && *pci_dev->configfd_name) {
-        if (qemu_isdigit(pci_dev->configfd_name[0])) {
-            dev->config_fd = strtol(pci_dev->configfd_name, NULL, 0);
-        } else {
-            dev->config_fd = monitor_get_fd(cur_mon, pci_dev->configfd_name);
-            if (dev->config_fd < 0) {
-                error_report("%s: (%s) unkown", __func__,
-                             pci_dev->configfd_name);
-                return 1;
-            }
+        dev->config_fd = monitor_handle_fd_param(cur_mon, pci_dev->configfd_name);
+        if (dev->config_fd < 0) {
+            return 1;
         }
     } else {
         dev->config_fd = open(name, O_RDWR);