1

I have the following piece of code (kernel code to be more specific):

static int is_sram_locked(void)
{
if (OMAP2_DEVICE_TYPE_GP == omap_type()) {
    /* RAMFW: R/W access to all initiators for all qualifier sets */
    if (cpu_is_omap242x()) {
        __raw_writel(0xFF, OMAP24XX_VA_REQINFOPERM0); /* all q-vects */
        __raw_writel(0xCFDE, OMAP24XX_VA_READPERM0);  /* all i-read */
        __raw_writel(0xCFDE, OMAP24XX_VA_WRITEPERM0); /* all i-write */
    }
    if (cpu_is_omap34xx() && !cpu_is_am33xx()) {
        __raw_writel(0xFFFF, OMAP34XX_VA_REQINFOPERM0); /* all q-vects */
        __raw_writel(0xFFFF, OMAP34XX_VA_READPERM0);  /* all i-read */
        __raw_writel(0xFFFF, OMAP34XX_VA_WRITEPERM0); /* all i-write */
        __raw_writel(0x0, OMAP34XX_VA_ADDR_MATCH2);
        __raw_writel(0xFFFFFFFF, OMAP34XX_VA_SMS_RG_ATT0);
    }
    return 0;
} else
    return 1; /* assume locked with no PPA or security driver */
}

This is copy-pasted from Sublime Text 3, and as the title states, I get the following compilation error:

error: stray '\302' in program error: stray '\273' in program

On lines that start with __raw_writel( ... )

I have done research about the problem and I found out that this error tells me that there is an unprintable character on the line as the cause.

'\302 \273' is UTF-8 code for '»' (RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK)

I read that this problem often appears when you copy-paste code from somewhere else and those unprintable characters may have skipped your attention or your keyboard has a different layout that types strange characters. I inspected the code very closely and I could not find any of those foreign characters.

My big question is: How can kernel code that I have never touched can present such errors? And I have more than one file that comes with this error, which brings me to the fact that there might be something else wrong.

I have figured it out that I get this error on lines that start with anything else but a letter such as : '_' and '.' (these are the examples that rise issues for me so far)

Solutions I have tried:

  • Re-writing the entire lines;
  • Copy-paste the code into many UTF-8 unprintable character filters so I can find the 'stray' characters
  • Unicode Character Highlighter Sublime Text packages

Note: I'm also using Vim as editor and my .vimrc puts '»' as Tabs and '·' as spaces, but only for indentation purposes, not as actual characters. I've fixed some similar errors when I copy-pasted from Vim and those characters were actually in text. I deleted the characters and it got fixed. But for this, I can't identify any 'stray' characters present in the code.

How can I fix it?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Pavel Daniel
  • 109
  • 1
  • 10
  • I've tried cat -vet program.c and no strange characters came up except ^I which means tab and $ which specifies the end of line. – Pavel Daniel Jun 22 '15 at 12:02
  • What do you compile your program with? – Eregrith Jun 22 '15 at 12:04
  • gcat if you are on a systemV unix – Peter Miehle Jun 22 '15 at 12:04
  • @Ergrith: arm2010q1 toolchain – Pavel Daniel Jun 22 '15 at 12:05
  • 1
    have you taken a look into the OMAP* defines? maybe there is the problem? – Peter Miehle Jun 22 '15 at 12:07
  • @Peter Miehle: I'm on Ubuntu 14.04. – Pavel Daniel Jun 22 '15 at 12:07
  • 1
    cat -e ` gcc -E program.c ` then :) – Eregrith Jun 22 '15 at 12:12
  • well `gcc -E` or the equivalent for your thing – Eregrith Jun 22 '15 at 12:12
  • @PeterMiehle: will take a loot at the defines. Thank you – Pavel Daniel Jun 22 '15 at 12:18
  • @Eregrith: I'm using a custom build system that uses make as a wrapper. I will try to do the -E thing. Will come back with results. – Pavel Daniel Jun 22 '15 at 12:18
  • 1
    Your questions implies that people don't read the questions they mark as duplicates! – Iharob Al Asimi Jun 22 '15 at 12:21
  • @PavelDaniel `gcc -E` option will do only the preprocessing on your code, replacing macros and including headers. This way you can see the whole source as it will be just before compilation. If there is an error in the macros or somewhere else, you should see it – Eregrith Jun 22 '15 at 12:23
  • 1
    I'm voting to close this question as off-topic because it is either a duplicate question or a question seeking debugging help that doesn't include the desired behaviour (see [how to create a minimal, compilable, and verifiable example](http://stackoverflow.com/help/mcve)) – autistic Jun 22 '15 at 12:28
  • @undefinedbehaviour: Agreed since my problem can't be reproduced. I don't see how I could do that. I was just asking for opinions on a matter I find no solution for. Thank you all for help. Have a great day! – Pavel Daniel Jun 22 '15 at 12:37
  • 1
    Check that the "stray" characters are not in the macro definitions for `OMAP24XX_VA_REQINFOPERM0` etc. That would explain their "invisibility" in the code posted and the fact that it occurs for every `__raw_writel()` call. Try a `__raw_writel()` without using one of those macros. – Clifford Jun 22 '15 at 12:47
  • There aren't ***any*** of the commonly encountered stray characters in the code as posted ([NO-BREAK SPACE](https://www.utf8-chartable.de/unicode-utf8-table.pl?utf8=0x), LEFT-POINTING DOUBLE ANGLE QUOTATION MARK, RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK, ZERO WIDTH SPACE, ZERO WIDTH NON-JOINER, ZERO WIDTH NO-BREAK SPACE, EN DASH, EM DASH, LEFT DOUBLE QUOTATION MARK, RIGHT DOUBLE QUOTATION MARK, MINUS SIGN, LATIN SMALL LETTER A WITH DIAERESIS, OBJECT REPLACEMENT CHARACTER, REPLACEMENT CHARACTER, ASTERISK OPERATOR, etc.) – Peter Mortensen May 01 '23 at 17:49
  • I think this should be closed a duplicate of the canonical (the likely reason for the error is the same: copying code from a web page or similar): *[Compilation error: stray ‘\302’ in program, etc.](https://stackoverflow.com/questions/19198332/)* – Peter Mortensen May 01 '23 at 17:56
  • This question is about [RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK](https://www.utf8-chartable.de/unicode-utf8-table.pl?start=128) (U+00BB). Here is [a question for *LEFT-POINTING DOUBLE ANGLE QUOTATION MARK*](https://stackoverflow.com/questions/37293679/drawing-polygon-with-qt) ([U+00AB](https://www.utf8-chartable.de/unicode-utf8-table.pl?start=128)). But it is probably unrelated, as they don't seem to come in pairs. However, the cause could be the same. Is there a particular system, CMS, application, etc. which is fond of using ««««««««««««« and »»»»»»»»»»»»»?? – Peter Mortensen May 01 '23 at 18:07
  • Or maybe it is a common occurrence when content in one encoding (e.g., [Windows-1250](https://en.wikipedia.org/wiki/Windows-1250)) is presumed to be in some other encoding (e.g., [UTF-8](https://en.wikipedia.org/wiki/UTF-8))? It must be well known in the web space. It is [hinted at here](https://stackoverflow.com/questions/18632791/compilation-error-error-stray-302-in-program-error-while-connecting-mysql/18632971#18632971) (also for RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK), but it is not very convincing. What is the explanation? – Peter Mortensen May 03 '23 at 12:48
  • Slightly related: *[List of all Unicode's open/close brackets](https://stackoverflow.com/questions/13535172/)*. And [Windows-1252](https://en.wikipedia.org/wiki/Windows-1252) is more common than Windows-1250 (but [not identical](https://stackoverflow.com/questions/20025030/convert-all-types-of-smart-quotes-with-php/21491305#21491305) to [ISO 8859-1](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)). RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK: AKA right pointing [guillemet](https://en.wikipedia.org/wiki/Guillemet). And HTML character entity reference `»`. – Peter Mortensen May 03 '23 at 13:09

1 Answers1

1

The macros were the problem. They referred to some macros I modified with some copy-paste code and completely forgot about it.

Special thanks to all.

Pavel Daniel
  • 109
  • 1
  • 10