Hi Laurent, Laurent Dufour <lduf...@linux.ibm.com> writes: > +/* > + * PAPR defines, in section "7.3.16 System Parameters Option", the token 55 > to > + * read the LPAR name. > + */ > +#define SPLPAR_LPAR_NAME_TOKEN 55 > +static void read_lpar_name(struct seq_file *m) > +{ > + int rc, len, token; > + union { > + char raw_buffer[RTAS_DATA_BUF_SIZE]; > + struct { > + __be16 len;
This: > + char name[RTAS_DATA_BUF_SIZE-2]; ^^^^^^ should be 4000, not (4K - 2), according to PAPR (it's weird and I don't know the reason). > + }; > + } *local_buffer; > + > + token = rtas_token("ibm,get-system-parameter"); > + if (token == RTAS_UNKNOWN_SERVICE) > + return; > + > + local_buffer = kmalloc(sizeof(*local_buffer), GFP_KERNEL); > + if (!local_buffer) > + return; > + > + do { > + spin_lock(&rtas_data_buf_lock); > + memset(rtas_data_buf, 0, RTAS_DATA_BUF_SIZE); > + rc = rtas_call(token, 3, 1, NULL, SPLPAR_LPAR_NAME_TOKEN, > + __pa(rtas_data_buf), RTAS_DATA_BUF_SIZE); > + if (!rc) > + memcpy(local_buffer->raw_buffer, rtas_data_buf, > + RTAS_DATA_BUF_SIZE); > + spin_unlock(&rtas_data_buf_lock); > + } while (rtas_busy_delay(rc)); > + > + if (rc != 0) { > + pr_err_once( > + "%s %s Error calling get-system-parameter (0x%x)\n", > + __FILE__, __func__, rc); The __FILE__ and __func__ in the message seem unnecessary, and rc should be reported in decimal so the error meaning is apparent. Is there a reasonable fallback for VMs where this parameter doesn't exist? PowerVM partitions should always have it, but what do we want the behavior to be on other hypervisors? > + } else { > + /* Force end of string */ > + len = be16_to_cpu(local_buffer->len); > + if (len >= (RTAS_DATA_BUF_SIZE-2)) > + len = RTAS_DATA_BUF_SIZE-2; Could use min() or clamp(), and it would be better to build the expression using the value of sizeof(local_buffer->name). > + local_buffer->name[len] = '\0'; If 'len' can be (RTAS_DATA_BUF_SIZE - 2), then this writes past the end of the buffer, no?