Skip to content

Commit 6f46b12

Browse files
committed
Merge branch 'x86-microcode-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip
* 'x86-microcode-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip: x86, microcode, AMD: Cleanup code a bit x86, microcode, AMD: Replace vmalloc+memset with vzalloc
2 parents 4e1db5e + c7657ac commit 6f46b12

2 files changed

Lines changed: 16 additions & 24 deletions

File tree

‎arch/x86/include/asm/microcode.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ static inline struct microcode_ops * __init init_intel_microcode(void)
4848

4949
#ifdef CONFIG_MICROCODE_AMD
5050
extern struct microcode_ops * __init init_amd_microcode(void);
51+
52+
static inline void get_ucode_data(void *to, const u8 *from, size_t n)
53+
{
54+
memcpy(to, from, n);
55+
}
56+
5157
#else
5258
static inline struct microcode_ops * __init init_amd_microcode(void)
5359
{

‎arch/x86/kernel/microcode_amd.c‎

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -155,21 +155,14 @@ static int apply_microcode_amd(int cpu)
155155
return 0;
156156
}
157157

158-
static int get_ucode_data(void *to, const u8 *from, size_t n)
159-
{
160-
memcpy(to, from, n);
161-
return 0;
162-
}
163-
164158
static void *
165159
get_next_ucode(const u8 *buf, unsigned int size, unsigned int *mc_size)
166160
{
167161
unsigned int total_size;
168162
u8 section_hdr[UCODE_CONTAINER_SECTION_HDR];
169163
void *mc;
170164

171-
if (get_ucode_data(section_hdr, buf, UCODE_CONTAINER_SECTION_HDR))
172-
return NULL;
165+
get_ucode_data(section_hdr, buf, UCODE_CONTAINER_SECTION_HDR);
173166

174167
if (section_hdr[0] != UCODE_UCODE_TYPE) {
175168
pr_err("error: invalid type field in container file section header\n");
@@ -183,16 +176,13 @@ get_next_ucode(const u8 *buf, unsigned int size, unsigned int *mc_size)
183176
return NULL;
184177
}
185178

186-
mc = vmalloc(UCODE_MAX_SIZE);
187-
if (mc) {
188-
memset(mc, 0, UCODE_MAX_SIZE);
189-
if (get_ucode_data(mc, buf + UCODE_CONTAINER_SECTION_HDR,
190-
total_size)) {
191-
vfree(mc);
192-
mc = NULL;
193-
} else
194-
*mc_size = total_size + UCODE_CONTAINER_SECTION_HDR;
195-
}
179+
mc = vzalloc(UCODE_MAX_SIZE);
180+
if (!mc)
181+
return NULL;
182+
183+
get_ucode_data(mc, buf + UCODE_CONTAINER_SECTION_HDR, total_size);
184+
*mc_size = total_size + UCODE_CONTAINER_SECTION_HDR;
185+
196186
return mc;
197187
}
198188

@@ -202,8 +192,7 @@ static int install_equiv_cpu_table(const u8 *buf)
202192
unsigned int *buf_pos = (unsigned int *)container_hdr;
203193
unsigned long size;
204194

205-
if (get_ucode_data(&container_hdr, buf, UCODE_CONTAINER_HEADER_SIZE))
206-
return 0;
195+
get_ucode_data(&container_hdr, buf, UCODE_CONTAINER_HEADER_SIZE);
207196

208197
size = buf_pos[2];
209198

@@ -219,10 +208,7 @@ static int install_equiv_cpu_table(const u8 *buf)
219208
}
220209

221210
buf += UCODE_CONTAINER_HEADER_SIZE;
222-
if (get_ucode_data(equiv_cpu_table, buf, size)) {
223-
vfree(equiv_cpu_table);
224-
return 0;
225-
}
211+
get_ucode_data(equiv_cpu_table, buf, size);
226212

227213
return size + UCODE_CONTAINER_HEADER_SIZE; /* add header length */
228214
}

0 commit comments

Comments
 (0)