Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should OP-TEE revision be printed as "string" in linux OP-TEE driver ? #7141

Open
sahilnxp opened this issue Nov 20, 2024 · 9 comments
Open

Comments

@sahilnxp
Copy link
Contributor

Since we have moved to 16bit sha1 len for OP-TEE revision in case of 64 bit architecture.

Should we print the revision as string in place of long int here

Observed one issue on 64 bit architectures, if the commit id is starting with 0 like 04d1c612ec7beaede073b8cad0f33a1f5ab9e2bc

It is printing revision as below removing leading 0.
2024-11-15T02:29:51.469317 [ 2.019585] optee: revision 4.4 (4d1c612ec7beaed)

@jforissier
Copy link
Contributor

Hi @sahilnxp,

Should we print the revision as string in place of long int here

I think the format simply needs adjusting to cater to the size of the unsigned long:

pr_info("revision %lu.%lu (%0*lx)", res.result.major,
	res.result.minor, sizeof(res.result.build_id) * 2,
	res.result.build_id);

@sahilnxp
Copy link
Contributor Author

Hi @sahilnxp,

Should we print the revision as string in place of long int here

I think the format simply needs adjusting to cater to the size of the unsigned long:

pr_info("revision %lu.%lu (%0*lx)", res.result.major,
	res.result.minor, sizeof(res.result.build_id) * 2,
	res.result.build_id);

Yes, that will work, but we need to pass the size like (16) too in this case like below:

pr_info("revision %lu.%lu (%0*lx)", res.result.major,
	res.result.minor, sizeof(res.result.build_id) * 2,
	16, res.result.build_id);

and how to decide on this size ? Otherwise, it is giving the following warning.

                 from drivers/tee/optee/smc_abi.c:12:
drivers/tee/optee/smc_abi.c: In function ‘optee_msg_get_os_revision’:
./include/linux/kern_levels.h:5:25: warning: field width specifier ‘*’ expects argument of type ‘int’, but argument 4 has type ‘long unsigned int’ [-Wformat=]
    5 | #define KERN_SOH        "\001"          /* ASCII Start Of Header */
      |                         ^~~~~~

@jenswi-linaro
Copy link
Contributor

Casting the size argument to int should work.

@sahilnxp
Copy link
Contributor Author

sahilnxp commented Nov 21, 2024

Sorry for confusion here.

There is no compilation warning in case of following code:

pr_info("revision %lu.%lu (%0*lx)", res.result.major,
	res.result.minor, sizeof(res.result.build_id) * 2,
	16, res.result.build_id);

But how we can decide if we should give the size as 8 (for 32bit arch) and 16 (for 64 bit arch) ?

@jforissier
Copy link
Contributor

Sorry for confusion here.

There is no compilation warning in case of following code:

pr_info("revision %lu.%lu (%0*lx)", res.result.major,
	res.result.minor, sizeof(res.result.build_id) * 2,
	16, res.result.build_id);

But how we can decide if we should give the size as 8 (for 32bit arch) and 16 (for 64 bit arch) ?

res.result.build_id is unsigned long. 32-bit arch have sizeof(unsigned long) == 4 while 64-bit arch have sizeof(unsigned long) == 8.

@sahilnxp
Copy link
Contributor Author

So it should be like this, right ?

pr_info("revision %lu.%lu (%0*lx)", res.result.major,
             res.result.minor, (int)sizeof(unsigned long),
             res.result.build_id);

@jforissier
Copy link
Contributor

No, because in the Linux (and OP-TEE) coding style, the argument of sizeof() should be the variable rather than the type. This makes sense to make maintenance easier in case the type is changed for instance.

@sahilnxp
Copy link
Contributor Author

In that case, it should be like below ?

pr_info("revision %lu.%lu (%0*lx)", res.result.major,
             res.result.minor, (int)sizeof(res.result.build_id),
             res.result.build_id);

@jforissier
Copy link
Contributor

In that case, it should be like below ?

pr_info("revision %lu.%lu (%0*lx)", res.result.major,
             res.result.minor, (int)sizeof(res.result.build_id),
             res.result.build_id);

No. The * 2 is missing. Here is exactly how the code should be:

	if (res.result.build_id)
		pr_info("revision %lu.%lu (%08lx)", res.result.major,
			res.result.minor, (int)sizeof(res.result.build_id) * 2,
			res.result.build_id);
	else
		pr_info("revision %lu.%lu", res.result.major, res.result.minor);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants