Skip to content

Commit 84d2594

Browse files
snitsJarkko Sakkinen
authored andcommitted
tpm: make check_locality return bool
Since check_locality is checking to see if a certain locality is active, return true if active otherwise return false. Cc: Christophe Ricard <[email protected]> Cc: Jason Gunthorpe <[email protected]> Cc: Marcel Selhorst <[email protected]> Cc: Jarkko Sakkinen <[email protected]> Cc: Peter Huewe <[email protected]> Signed-off-by: Jerry Snitselaar <[email protected]> Reviewed-by: Jarkko Sakkinen <[email protected]> Tested-by: Jarkko Sakkinen <[email protected]> Signed-off-by: Jarkko Sakkinen <[email protected]>
1 parent 67c2f3d commit 84d2594

File tree

3 files changed

+23
-21
lines changed

3 files changed

+23
-21
lines changed

drivers/char/tpm/st33zp24/st33zp24.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ static u8 st33zp24_status(struct tpm_chip *chip)
117117
/*
118118
* check_locality if the locality is active
119119
* @param: chip, the tpm chip description
120-
* @return: the active locality or -EACCESS.
120+
* @return: true if LOCALITY0 is active, otherwise false
121121
*/
122-
static int check_locality(struct tpm_chip *chip)
122+
static bool check_locality(struct tpm_chip *chip)
123123
{
124124
struct st33zp24_dev *tpm_dev = dev_get_drvdata(&chip->dev);
125125
u8 data;
@@ -129,9 +129,9 @@ static int check_locality(struct tpm_chip *chip)
129129
if (status && (data &
130130
(TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) ==
131131
(TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID))
132-
return tpm_dev->locality;
132+
return true;
133133

134-
return -EACCES;
134+
return false;
135135
} /* check_locality() */
136136

137137
/*
@@ -146,7 +146,7 @@ static int request_locality(struct tpm_chip *chip)
146146
long ret;
147147
u8 data;
148148

149-
if (check_locality(chip) == tpm_dev->locality)
149+
if (check_locality(chip))
150150
return tpm_dev->locality;
151151

152152
data = TPM_ACCESS_REQUEST_USE;
@@ -158,7 +158,7 @@ static int request_locality(struct tpm_chip *chip)
158158

159159
/* Request locality is usually effective after the request */
160160
do {
161-
if (check_locality(chip) >= 0)
161+
if (check_locality(chip))
162162
return tpm_dev->locality;
163163
msleep(TPM_TIMEOUT);
164164
} while (time_before(jiffies, stop));

drivers/char/tpm/tpm_i2c_infineon.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -278,22 +278,22 @@ enum tis_defaults {
278278
#define TPM_DATA_FIFO(l) (0x0005 | ((l) << 4))
279279
#define TPM_DID_VID(l) (0x0006 | ((l) << 4))
280280

281-
static int check_locality(struct tpm_chip *chip, int loc)
281+
static bool check_locality(struct tpm_chip *chip, int loc)
282282
{
283283
u8 buf;
284284
int rc;
285285

286286
rc = iic_tpm_read(TPM_ACCESS(loc), &buf, 1);
287287
if (rc < 0)
288-
return rc;
288+
return false;
289289

290290
if ((buf & (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) ==
291291
(TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) {
292292
tpm_dev.locality = loc;
293-
return loc;
293+
return true;
294294
}
295295

296-
return -EIO;
296+
return false;
297297
}
298298

299299
/* implementation similar to tpm_tis */
@@ -315,15 +315,15 @@ static int request_locality(struct tpm_chip *chip, int loc)
315315
unsigned long stop;
316316
u8 buf = TPM_ACCESS_REQUEST_USE;
317317

318-
if (check_locality(chip, loc) >= 0)
318+
if (check_locality(chip, loc))
319319
return loc;
320320

321321
iic_tpm_write(TPM_ACCESS(loc), &buf, 1);
322322

323323
/* wait for burstcount */
324324
stop = jiffies + chip->timeout_a;
325325
do {
326-
if (check_locality(chip, loc) >= 0)
326+
if (check_locality(chip, loc))
327327
return loc;
328328
usleep_range(TPM_TIMEOUT_US_LOW, TPM_TIMEOUT_US_HI);
329329
} while (time_before(jiffies, stop));

drivers/char/tpm/tpm_tis_core.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,23 @@ static int wait_startup(struct tpm_chip *chip, int l)
5656
return -1;
5757
}
5858

59-
static int check_locality(struct tpm_chip *chip, int l)
59+
static bool check_locality(struct tpm_chip *chip, int l)
6060
{
6161
struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
6262
int rc;
6363
u8 access;
6464

6565
rc = tpm_tis_read8(priv, TPM_ACCESS(l), &access);
6666
if (rc < 0)
67-
return rc;
67+
return false;
6868

6969
if ((access & (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) ==
70-
(TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID))
71-
return priv->locality = l;
70+
(TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) {
71+
priv->locality = l;
72+
return true;
73+
}
7274

73-
return -1;
75+
return false;
7476
}
7577

7678
static void release_locality(struct tpm_chip *chip, int l, int force)
@@ -96,7 +98,7 @@ static int request_locality(struct tpm_chip *chip, int l)
9698
unsigned long stop, timeout;
9799
long rc;
98100

99-
if (check_locality(chip, l) >= 0)
101+
if (check_locality(chip, l))
100102
return l;
101103

102104
rc = tpm_tis_write8(priv, TPM_ACCESS(l), TPM_ACCESS_REQUEST_USE);
@@ -112,7 +114,7 @@ static int request_locality(struct tpm_chip *chip, int l)
112114
return -1;
113115
rc = wait_event_interruptible_timeout(priv->int_queue,
114116
(check_locality
115-
(chip, l) >= 0),
117+
(chip, l)),
116118
timeout);
117119
if (rc > 0)
118120
return l;
@@ -123,7 +125,7 @@ static int request_locality(struct tpm_chip *chip, int l)
123125
} else {
124126
/* wait for burstcount */
125127
do {
126-
if (check_locality(chip, l) >= 0)
128+
if (check_locality(chip, l))
127129
return l;
128130
msleep(TPM_TIMEOUT);
129131
} while (time_before(jiffies, stop));
@@ -535,7 +537,7 @@ static irqreturn_t tis_int_handler(int dummy, void *dev_id)
535537
wake_up_interruptible(&priv->read_queue);
536538
if (interrupt & TPM_INTF_LOCALITY_CHANGE_INT)
537539
for (i = 0; i < 5; i++)
538-
if (check_locality(chip, i) >= 0)
540+
if (check_locality(chip, i))
539541
break;
540542
if (interrupt &
541543
(TPM_INTF_LOCALITY_CHANGE_INT | TPM_INTF_STS_VALID_INT |

0 commit comments

Comments
 (0)