Skip to content

Commit b6bb44f

Browse files
PeterHuewegregkh
authored andcommitted
tpm/tpm_ppi: Do not compare strcmp(a,b) == -1
commit 747d35b upstream. Depending on the implementation strcmp might return the difference between two strings not only -1,0,1 consequently if (strcmp (a,b) == -1) might lead to taking the wrong branch -> compare with < 0 instead, which in any case is more canonical. Signed-off-by: Peter Huewe <peterhuewe@gmx.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 5ef2e9b commit b6bb44f

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

‎drivers/char/tpm/tpm_ppi.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ static ssize_t tpm_store_ppi_request(struct device *dev,
172172
* is updated with function index from SUBREQ to SUBREQ2 since PPI
173173
* version 1.1
174174
*/
175-
if (strcmp(version, "1.1") == -1)
175+
if (strcmp(version, "1.1") < 0)
176176
params[2].integer.value = TPM_PPI_FN_SUBREQ;
177177
else
178178
params[2].integer.value = TPM_PPI_FN_SUBREQ2;
@@ -182,7 +182,7 @@ static ssize_t tpm_store_ppi_request(struct device *dev,
182182
* string/package type. For PPI version 1.0 and 1.1, use buffer type
183183
* for compatibility, and use package type since 1.2 according to spec.
184184
*/
185-
if (strcmp(version, "1.2") == -1) {
185+
if (strcmp(version, "1.2") < 0) {
186186
params[3].type = ACPI_TYPE_BUFFER;
187187
params[3].buffer.length = sizeof(req);
188188
sscanf(buf, "%d", &req);
@@ -248,7 +248,7 @@ static ssize_t tpm_show_ppi_transition_action(struct device *dev,
248248
* (e.g. Capella with PPI 1.0) need integer/string/buffer type, so for
249249
* compatibility, define params[3].type as buffer, if PPI version < 1.2
250250
*/
251-
if (strcmp(version, "1.2") == -1) {
251+
if (strcmp(version, "1.2") < 0) {
252252
params[3].type = ACPI_TYPE_BUFFER;
253253
params[3].buffer.length = 0;
254254
params[3].buffer.pointer = NULL;
@@ -390,7 +390,7 @@ static ssize_t show_ppi_operations(char *buf, u32 start, u32 end)
390390
kfree(output.pointer);
391391
output.length = ACPI_ALLOCATE_BUFFER;
392392
output.pointer = NULL;
393-
if (strcmp(version, "1.2") == -1)
393+
if (strcmp(version, "1.2") < 0)
394394
return -EPERM;
395395

396396
params[2].integer.value = TPM_PPI_FN_GETOPR;

0 commit comments

Comments
 (0)