Re: RE: [EXTERNAL] Re: [PATCH v10] ASoC: tas2781: Add tas2781 driver

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Le 05/04/2023 à 13:21, Ding, Shenghao a écrit :
Hi Both
I wrote a test code to verify the be32_to_cpu & be32_to_cpup,
static int __init lkm_init(void)
{
	char test_buf[]={0x12, 0x34, 0xab, 0xbc, 0x56, 0x78, 0xef};
	unsigned int *k, p, q;
	int i;

	printk("Hello, Shanghai!\n");

	for (i = 0; i < 4; i ++) {
		k = (unsigned int *)&test_buf[i];
		p = be32_to_cpup((__be32 *)k);
		q = be32_to_cpu(test_buf[i]);
		printk("%d: *k = 0x%08x p = 0x%08x q = 0x%08x %ld\n",
			i, *k, p, q, sizeof(unsigned int));
	}
	return 0;
}
The output is:
[ 9109.722548] Hello, Shanghai!
[ 9109.726287] 0: *k = 0xbcab3412 p = 0x1234abbc q = 0x12000000 4
[ 9109.727665] 1: *k = 0x56bcab34 p = 0x34abbc56 q = 0x34000000 4
[ 9109.728553] 2: *k = 0x7856bcab p = 0xabbc5678 q = 0xabffffff 4
[ 9109.729308] 3: *k = 0xef7856bc p = 0xbc5678ef q = 0xbcffffff 4
Apparently, be32_to_cpup's output is what I expected.
Looking forward to your comments. Thanks.

Hi,

thanks for the clarification and code sample.
You are right.

I had in mind that something like: be32_to_cpu((__be32 *)data);
would make it. (thanks to the cast)

But because of the need of "&" and "[offset]", it would just make the code unnecessarily complex.

I think that your approach is better.

CJ



[Index of Archives]     [ALSA User]     [Linux Audio Users]     [Pulse Audio]     [Kernel Archive]     [Asterisk PBX]     [Photo Sharing]     [Linux Sound]     [Video 4 Linux]     [Gimp]     [Yosemite News]

  Powered by Linux