简体   繁体   English

它是Linux的SD卡驱动程序的错误吗

[英]Is it a bug of SD card driver for Linux

I found something strange in SD card driver for Linux. 我在Linux的SD卡驱动程序中发现了一些奇怪的东西。 The driver reads card status in the function mmc_read_ssr in file drivers/mmc/core/sd.c . 该驱动器读取功能卡状态mmc_read_ssr文件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 当函数mmc_app_sd_status返回表示错误的值时,该错误将被清除

err = 0;

Why should the error be cleared when error happens in reading SSR? 读取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. 我对Linux的SD驱动程序了解不多,但是根据我(有限的)内核开发经验,您总是在与CPU和内存使用情况,硬件错误,编译器“功能”等“可读代码”作斗争。 。

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; ). 我必须承认,它确实看起来像是个意外-因为它总是返回零(尽管声明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. 错误值由调用它的代码检查(在mmc_sd_setup_card()内部)-如果它始终为零,则再次没有意义。

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"? 从推测上讲,也许某些特别古老的SD硬件“错误地”运行,并且尽管“一切都很好”,却引发了错误抛出? 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). 否则,我只是建议问一个人口稠密的Linux内核开发者论坛(IRC或邮件列表等)。 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... 不过,这是一个好问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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