简体   繁体   中英

Is it a bug of SD card driver for Linux

I found something strange in SD card driver for Linux. The driver reads card status in the function mmc_read_ssr in file drivers/mmc/core/sd.c . The codes are as below:

err = mmc_app_sd_status(card, ssr);
if (err) {
    pr_warning("%s: problem reading SD Status "
        "register.\n", mmc_hostname(card->host));
    err = 0;
    goto out;
}

When the function mmc_app_sd_status return a value indicating error, the error is cleared in

err = 0;

Why should the error be cleared when error happens in reading SSR?

When I look at other people's code, especially code of people who I know are really good at what they do, I apply the "Assume I'm wrong" attitude.

I don't know a great deal about the SD drivers in Linux - but from my (limited) experience in kernel development, you're always battling "readable code" with CPU and memory usage, hardware bugs, compiler "features", etc.

You'll notice it does do a little more than "clear" the error value - it skips the entire block of what follows. (Presumably because it knows it'll fail.)

I must confess it does look like an accident - as it always returns zero (despite stating return err; ). The error value is checked by the code which calls it (inside mmc_sd_setup_card() ) - which is again pointless if it's always zero.

All that does happen (from what I can see) is a kernel warning is printed. As I said, I always adopt an "assume I'm wrong" attitude, so I'll assume whoever wrote the code (or came along and patched it most recently) deemed that the "warning" wasn't enough to justify throwing an error code. So they left it writing to the kernel logs and let "whatever happen, happen".

Speculatively, perhaps some particularly archaic SD hardware acts "wrongly" and was causing an error to throw despite "everything being OK"? Device drivers often have hacks throughout them to deal with such edge case scenarios.

Otherwise I'd just suggest asking a well populated Linux kernel dev forum (IRC or mailing list, etc). Be polite, make it clear you "assume you're wrong" and don't be surprised if you get an abrupt or rude-sounding response!

A good question though...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM