linux-ide.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* re: libata: check zero power ready status for ZPODD
@ 2016-04-14  9:30 Dan Carpenter
  2016-04-15  2:34 ` Aaron Lu
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2016-04-14  9:30 UTC (permalink / raw)
  To: aaron.lu; +Cc: linux-ide

Hello Aaron Lu,

The patch 3dc67440d99b: "libata: check zero power ready status for
ZPODD" from Jan 15, 2013, leads to the following static checker
warning:

	drivers/ata/libata-zpodd.c:97 zpready()
	error: uninitialized symbol 'sense_key'.

drivers/ata/libata-zpodd.c
    88  /* Test if ODD is zero power ready by sense code */
    89  static bool zpready(struct ata_device *dev)
    90  {
    91          u8 sense_key, *sense_buf;
    92          unsigned int ret, asc, ascq, add_len;
    93          struct zpodd *zpodd = dev->zpodd;
    94  
    95          ret = atapi_eh_tur(dev, &sense_key);
    96  
    97          if (!ret || sense_key != NOT_READY)
    98                  return false;

It's not clear what is going on here.  atapi_eh_tur() returns 0 on
success or a bit mask on error.  If the AC_ERR_DEV (which is BIT(0)) bit
is set and no other bits then we set "&sense_key" otherwise it is
uninitialized.

So maybe the test should be:

	if (ret != AC_ERR_DEV || sense_key != NOT_READY)
		return false;

That would silence the uninitialized variable warning but it's sort of
weird.  You would normall expect to return for errors and continue if
ret were zero.

	if (ret && !(ret == AC_ERR_DEV && ...

    99  
   100          sense_buf = dev->link->ap->sector_buf;
   101          ret = atapi_eh_request_sense(dev, sense_buf, sense_key);
   102          if (ret)
   103                  return false;

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: libata: check zero power ready status for ZPODD
  2016-04-14  9:30 libata: check zero power ready status for ZPODD Dan Carpenter
@ 2016-04-15  2:34 ` Aaron Lu
  0 siblings, 0 replies; 2+ messages in thread
From: Aaron Lu @ 2016-04-15  2:34 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: linux-ide

On 04/14/2016 05:30 PM, Dan Carpenter wrote:
> Hello Aaron Lu,
> 
> The patch 3dc67440d99b: "libata: check zero power ready status for
> ZPODD" from Jan 15, 2013, leads to the following static checker
> warning:
> 
> 	drivers/ata/libata-zpodd.c:97 zpready()
> 	error: uninitialized symbol 'sense_key'.
> 
> drivers/ata/libata-zpodd.c
>     88  /* Test if ODD is zero power ready by sense code */
>     89  static bool zpready(struct ata_device *dev)

This function returns true if ODD is zero power ready, false otherwise.

>     90  {
>     91          u8 sense_key, *sense_buf;
>     92          unsigned int ret, asc, ascq, add_len;
>     93          struct zpodd *zpodd = dev->zpodd;
>     94  
>     95          ret = atapi_eh_tur(dev, &sense_key);
>     96  
>     97          if (!ret || sense_key != NOT_READY)
>     98                  return false;

The pre-condition that the ODD can be considered zero power ready is:
there is no medium inside(hence, atapi_eh_tur should return a failure)
and the sense_key is set to NOT_READY. If the pre-condition is not
met as is checked by the above if, we return false.

> 
> It's not clear what is going on here.  atapi_eh_tur() returns 0 on
> success or a bit mask on error.  If the AC_ERR_DEV (which is BIT(0)) bit
> is set and no other bits then we set "&sense_key" otherwise it is
> uninitialized.

Good point, thanks for the catch.

> 
> So maybe the test should be:
> 
> 	if (ret != AC_ERR_DEV || sense_key != NOT_READY)
> 		return false;

I think I will simply set sense_key to zero beforehand instead of
changing the condition logic here, and it follows the other usage of the
atapi_eh_tur in atapi_eh_clear_ua where the sense_key is also set to 0
beforehand.


>From dda5c9306920ef973c9bf42db7723b86ab8b2930 Mon Sep 17 00:00:00 2001
From: Aaron Lu <aaron.lu@intel.com>
Date: Fri, 15 Apr 2016 10:30:32 +0800
Subject: [PATCH] libata: zpodd: initialize sense_key

The sense_key could be uninitialized after the call to atapi_eh_tur so
initialize it beforehand.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Aaron Lu <aaron.lu@intel.com>
---
 drivers/ata/libata-zpodd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/ata/libata-zpodd.c b/drivers/ata/libata-zpodd.c
index f3a65a3140d3..b0d3ea5f4769 100644
--- a/drivers/ata/libata-zpodd.c
+++ b/drivers/ata/libata-zpodd.c
@@ -88,7 +88,7 @@ static enum odd_mech_type zpodd_get_mech_type(struct ata_device *dev)
 /* Test if ODD is zero power ready by sense code */
 static bool zpready(struct ata_device *dev)
 {
-	u8 sense_key, *sense_buf;
+	u8 sense_key = 0, *sense_buf;
 	unsigned int ret, asc, ascq, add_len;
 	struct zpodd *zpodd = dev->zpodd;
 
-- 
2.5.5


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-04-15  2:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-04-14  9:30 libata: check zero power ready status for ZPODD Dan Carpenter
2016-04-15  2:34 ` Aaron Lu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).