diff mbox

ide: avoid referencing NULL dev in rotational rate setting

Message ID 20171020091403.1479-1-berrange@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Daniel P. Berrangé Oct. 20, 2017, 9:14 a.m. UTC
The 'dev' variable can be NULL when the guest OS calls identify on an IDE
unit that does not have a drive attached to it.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
---
 hw/ide/core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Stefan Hajnoczi Oct. 20, 2017, 9:34 a.m. UTC | #1
On Fri, Oct 20, 2017 at 10:14:03AM +0100, Daniel P. Berrange wrote:
> The 'dev' variable can be NULL when the guest OS calls identify on an IDE
> unit that does not have a drive attached to it.
> 
> Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
> ---
>  hw/ide/core.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Daniel P. Berrangé Oct. 24, 2017, 7:43 a.m. UTC | #2
CC John

On Fri, Oct 20, 2017 at 10:14:03AM +0100, Daniel P. Berrange wrote:
> The 'dev' variable can be NULL when the guest OS calls identify on an IDE
> unit that does not have a drive attached to it.
> 
> Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
> ---
>  hw/ide/core.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/ide/core.c b/hw/ide/core.c
> index a04766aee7..471d0c928b 100644
> --- a/hw/ide/core.c
> +++ b/hw/ide/core.c
> @@ -208,7 +208,9 @@ static void ide_identify(IDEState *s)
>      if (dev && dev->conf.discard_granularity) {
>          put_le16(p + 169, 1); /* TRIM support */
>      }
> -    put_le16(p + 217, dev->rotation_rate); /* Nominal media rotation rate */
> +    if (dev) {
> +        put_le16(p + 217, dev->rotation_rate); /* Nominal media rotation rate */
> +    }
>  
>      ide_identify_size(s);
>      s->identify_set = 1;
> -- 
> 2.13.6
> 

Regards,
Daniel
Stefan Hajnoczi Oct. 24, 2017, 12:20 p.m. UTC | #3
On Tue, Oct 24, 2017 at 08:43:24AM +0100, Daniel P. Berrange wrote:
> CC John

Feel free to ping me if John doesn't respond by next Wednesday and I'll
merge this trivial fix.

Stefan
diff mbox

Patch

diff --git a/hw/ide/core.c b/hw/ide/core.c
index a04766aee7..471d0c928b 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -208,7 +208,9 @@  static void ide_identify(IDEState *s)
     if (dev && dev->conf.discard_granularity) {
         put_le16(p + 169, 1); /* TRIM support */
     }
-    put_le16(p + 217, dev->rotation_rate); /* Nominal media rotation rate */
+    if (dev) {
+        put_le16(p + 217, dev->rotation_rate); /* Nominal media rotation rate */
+    }
 
     ide_identify_size(s);
     s->identify_set = 1;