Hi Geoff,

On 18/09/2020 04:04, Geoff Levand wrote:
Hi Matthias,

On 9/17/20 12:38 PM, [email protected] wrote:
Add option to allow purgatory printing on arm64 hardware
by passing the console name which should be used.

+static uint64_t find_purgatory_sink(const char *console)
+{
+       int fd, ret;
+       char folder[255], device[255], mem[255];
+       struct stat sb;
+       char buffer[18];
+       uint64_t iomem = 0x0;
+
+       if (!console)
+               return 0;
+
+       sprintf(device, "/sys/class/tty/%s", console);
+       if (!stat(folder, &sb) == 0 && S_ISDIR(sb.st_mode)) {
+               fprintf(stderr, "kexec: %s: No valid console found for %s\n",
+                       __func__, device);
+               return 0;
+       }
+
+       sprintf(mem, "%s%s", device, "/iomem_base");
+       printf("console memory read from %s\n", mem);
+
+       fd = open(mem, O_RDONLY);
+       if (fd < 0) {
+               fprintf(stderr, "kexec: %s: No able to open %s\n",
+                       __func__, mem);
+               return 0;
+       }
+
+       memset(buffer, '\0', sizeof(char) * 18);

I think I'd like to just see 'memset(buffer, 0, sizeof(buffer));'.

+       ret = read(fd, buffer, 18);

And 'ret = read(fd, buffer, sizeof(buffer));'.


You are correct, I'll add it to v2.

Thanks for the quick review!

Matthias

+       if (ret < 0) {
+               fprintf(stderr, "kexec: %s: not able to read fd\n", __func__);
+               close(fd);
+               return 0;
+       }
+
+       sscanf(buffer, "%lx", &iomem);
+       printf("console memory is at %#lx\n", iomem);
+
+       close(fd);
+       return iomem;
+}
+

Otherwise, looks OK.

-Geoff


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

Reply via email to