메모리 write ?? warning ...좀 찾아주세요

chxooi의 이미지


메모리 버퍼 디바이스 드라이버 작성중인데요

에러가나는데 원인을 모르겠네요...

ssize_t ram_read(uint32_t partition_id, char * buf, size_t count, loff_t  offset)
{       
#if 1/*test*/
 
    copy_to_user(buf,memory_buffer,1);
 
    /* Changing reading position as best suits */
    if (offset == 0) {  
        offset=1;  
        return 1;
    } else {  
        return 0;  
    }   
#endif  
    return count;
}
 
ssize_t ram_write( uint32_t partition_id, const char * buf, size_t count, loff_t offset)
{
#if 1
    char *tmp;
 
    tmp=buf+count-1;
    copy_from_user(memory_buffer,tmp,1);
    return 1;
#endif
    return count;
}

에러가 나는 부분은

tmp=buf+count-1 이부분인데 Error 는 아니고 Warning 으로 나오네요...

:148: warning: assignment discards qualifiers from pointer target type

뭐가 잘못된걸까요???

참고한 코드는

http://www.joinc.co.kr/modules/moniwiki/wiki.php/Site/Embedded/Documents/WritingDeviceDriversInLinux

여기서 가지고 왔습니다.

라스코니의 이미지

buf 는 const char *, 즉 상수 포인터형입니다.
그리고 tmp 는 그냥 char * 형이고요.

아마, buf 와 tmp 의 형이 달라고 그런 경고가 떴을 겁니다.

tmp = (char *)buf+count-1;

로 해주면 아마(자신은 없네요....) 경고는 제거될 겁니다.

stypr의 이미지

어떤 컴파일러 옵션을 쓰냐에 따라서 위 내용이 맞을 수도 틀릴 수도 있습니다. const char *를 char * 로 강제 변환하여도 다른 경고가 날 듯 합니다. 차라리 함수 인자 자체를 char * 로 변경을 하는게 좋을 듯 합니다.

ymir의 이미지

char *tmp; 를 const char *tmp; 로 바꿔주시는게 맞겠네요.
const 로 넘어온 얘는 중간에 const 가 보장되도록 코드를 작성하는 것이 좋습니다.
실질적으로 tmp 의 내용 변경없이 read-only 로 사용한다 하더라도..
문법상 const 로 한정한 변수들은 명시적으로 const 로 지정해 주는 것이 코딩 미스를 줄일 수 있습니다.

되면 한다! / feel no sorrow, feel no pain, feel no hurt, there's nothing gained.. only love will then remain.. 『 Mizz 』

되면 한다! / feel no sorrow, feel no pain, feel no hurt, there's nothing gained.. only love will then remain.. 『 Mizz 』

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.