Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

powerpc/powernv: Fix endian issues with OPAL async code

OPAL defines opal_msg as a big endian struct so we have to
byte swap it on little endian builds.

Signed-off-by: Anton Blanchard <anton@samba.org>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>

authored by

Anton Blanchard and committed by
Benjamin Herrenschmidt
bb4398e1 32b941b7

+16 -13
+3 -3
arch/powerpc/include/asm/opal.h
··· 422 422 }; 423 423 424 424 struct opal_msg { 425 - uint32_t msg_type; 426 - uint32_t reserved; 427 - uint64_t params[8]; 425 + __be32 msg_type; 426 + __be32 reserved; 427 + __be64 params[8]; 428 428 }; 429 429 430 430 struct opal_machine_check_event {
+4 -3
arch/powerpc/platforms/powernv/opal-async.c
··· 125 125 { 126 126 struct opal_msg *comp_msg = msg; 127 127 unsigned long flags; 128 + uint64_t token; 128 129 129 130 if (msg_type != OPAL_MSG_ASYNC_COMP) 130 131 return 0; 131 132 132 - memcpy(&opal_async_responses[comp_msg->params[0]], comp_msg, 133 - sizeof(*comp_msg)); 133 + token = be64_to_cpu(comp_msg->params[0]); 134 + memcpy(&opal_async_responses[token], comp_msg, sizeof(*comp_msg)); 134 135 spin_lock_irqsave(&opal_async_comp_lock, flags); 135 - __set_bit(comp_msg->params[0], opal_async_complete_map); 136 + __set_bit(token, opal_async_complete_map); 136 137 spin_unlock_irqrestore(&opal_async_comp_lock, flags); 137 138 138 139 wake_up(&opal_async_wait);
+1 -1
arch/powerpc/platforms/powernv/opal-sensor.c
··· 53 53 goto out_token; 54 54 } 55 55 56 - ret = msg.params[1]; 56 + ret = be64_to_cpu(msg.params[1]); 57 57 58 58 out_token: 59 59 mutex_unlock(&opal_sensor_mutex);
+2 -2
arch/powerpc/platforms/powernv/opal-sysparam.c
··· 64 64 goto out_token; 65 65 } 66 66 67 - ret = msg.params[1]; 67 + ret = be64_to_cpu(msg.params[1]); 68 68 69 69 out_token: 70 70 opal_async_release_token(token); ··· 98 98 goto out_token; 99 99 } 100 100 101 - ret = msg.params[1]; 101 + ret = be64_to_cpu(msg.params[1]); 102 102 103 103 out_token: 104 104 opal_async_release_token(token);
+6 -4
arch/powerpc/platforms/powernv/opal.c
··· 281 281 * value in /proc/device-tree. 282 282 */ 283 283 static struct opal_msg msg; 284 + u32 type; 284 285 285 286 ret = opal_get_msg(__pa(&msg), sizeof(msg)); 286 287 /* No opal message pending. */ ··· 295 294 return; 296 295 } 297 296 297 + type = be32_to_cpu(msg.msg_type); 298 + 298 299 /* Sanity check */ 299 - if (msg.msg_type > OPAL_MSG_TYPE_MAX) { 300 - pr_warning("%s: Unknown message type: %u\n", 301 - __func__, msg.msg_type); 300 + if (type > OPAL_MSG_TYPE_MAX) { 301 + pr_warning("%s: Unknown message type: %u\n", __func__, type); 302 302 return; 303 303 } 304 - opal_message_do_notify(msg.msg_type, (void *)&msg); 304 + opal_message_do_notify(type, (void *)&msg); 305 305 } 306 306 307 307 static int opal_message_notify(struct notifier_block *nb,