On 2022/01/03 10:26, Dmitry Osipenko wrote: > 03.01.2022 03:41, Hector Martin пишет: >>> There is indeed no need for the castings in such cases, it's a typical >>> code pattern in kernel. You would need to do the casting for the other >>> way around, i.e. if char ** was returned and **alt_paths was a const. >> You do need to do the cast. Try it. >> >> $ cat test.c >> int main() { >> char *foo[1]; >> const char **bar = foo; >> >> return 0; >> } >> >> $ gcc test.c >> test.c: In function ‘main’: >> test.c:4:28: warning: initialization of ‘const char **’ from >> incompatible pointer type ‘char **’ [-Wincompatible-pointer-types] >> 4 | const char **bar = foo; >> | >> >> You can implicitly cast char* to const char*, but you *cannot* >> impliclicitly cast char** to const char** for the reason I explained. It >> requires a cast. > > Right, I read it as "char * const *". The "const char **" vs "char * > const *" always confuses me. > > Hence you should've written "const char **alt_paths;" in > brcm_alt_fw_paths() in the first place and then casting wouldn't have > been needed. Sure, in this case that works since the string is just strduped and never mutated. Either way this will change to an argument instead of a return value, since I'll change it to be statically sized as you said and allocated by the caller (or in the struct). -- Hector Martin (marcan@xxxxxxxxx) Public Key: https://mrcn.st/pub