<p>I am attempting to copy a custom struct from kernel space to user space. inside user space errno returns 'bad address'.  What is the usual cause of a bad address error?</p>

<pre><code>if(copy_to_user(info, &amp;kernel_info, sizeof(struct prinfo)))
</code></pre>

[{'answer_id': 61948, 'author': 'roo', 'author_id': 716, 'author_profile': 'https://Stackoverflow.com/users/716', 'pm_score': 3, 'selected': False, 'text': "<p>Bad Address error means that the address location that you have given is invalid. With the case you have above I would guess it is because you are passing a copy of <code>info</code> instead of a pointer to <code>info</code>'s memory location.</p>\n\n<p>Looking at the docs, <code>copy_to_user</code> is defined as</p>\n\n<pre><code>copy_to_user(void __user * to, const void * from, unsigned long n);\n</code></pre>\n\n<p>So unless your <code>info</code> variable is a pointer I would update your code to be:</p>\n\n<pre><code>if(copy_to_user(&amp;info, &amp;kernel_info, sizeof(struct prinfo)) ) {\n    //some stuff here i guess\n}\n</code></pre>\n"}, {'answer_id': 74144, 'author': 'Frosty', 'author_id': 7476, 'author_profile': 'https://Stackoverflow.com/users/7476', 'pm_score': 2, 'selected': False, 'text': '<p>Assuming that info is a pointer type and that info is pointing to a valid location it is still possible that info is pointing to an address that is not in user space which is required by the function.</p>\n'}, {'answer_id': 29774005, 'author': 'Vijay Kumar Kanta', 'author_id': 1103688, 'author_profile': 'https://Stackoverflow.com/users/1103688', 'pm_score': -1, 'selected': False, 'text': '<p>I had a same problem while writing a small char driver. All I was doing wrong was the function copy_to_user returns non-zero on failure, so you have to do this..</p>\n\n<pre><code>if(copy_to_user(void *userbuf, void *kernelbuf, long len))\n    return -EFAULT;\n\n// Continue with code..\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/61893', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']