From: Mark Lord <liml@rtr.ca>
To: Tejun Heo <tj@kernel.org>, Jeff Garzik <jgarzik@pobox.com>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>,
IDE/ATA development list <linux-ide@vger.kernel.org>
Subject: [PATCH] libata-core More robust parsing for multi_count(v4)
Date: Thu, 19 Mar 2009 13:30:27 -0400 [thread overview]
Message-ID: <49C28133.8050401@rtr.ca> (raw)
In-Reply-To: <49C190F1.7010202@kernel.org>
Make libata more robust when parsing the multi_count
field from a drive's identify data. This prevents us from
attempting to use dubious multi_count values ad infinitum.
Reset dev->multi_count to zero and reprobe it each time
through this routine, as it can change on device reset.
Also ensure that the reported "maximum" value is valid
and is a power of two, and that the reported "count" value
is valid and also a power of two. And that the "count"
value is not greater than the "maximum" value.
Signed-off-by: Mark Lord <mlord@pobox.com>
---
Updated to use is_power_of_2() as suggested by Tejun.
Make libata more robust when parsing the multi_count
field from a drive's identify data. This prevents us from
attempting to use dubious multi_count values ad infinitum.
Reset dev->multi_count to zero and reprobe it each time
through this routine, as it can change on device reset.
Also ensure that the reported "maximum" value is valid
and is a power of two, and that the reported "count" value
is valid and also a power of two. And that the "count"
value is not greater than the "maximum" value.
Signed-off-by: Mark Lord <mlord@pobox.com>
---
Updated to use is_power_of_2() as suggested by Tejun.
--- upstream/drivers/ata/libata-core.c 2009-03-18 11:08:27.000000000 -0400
+++ new/drivers/ata/libata-core.c 2009-03-19 13:21:46.000000000 -0400
@@ -2389,6 +2389,7 @@
dev->cylinders = 0;
dev->heads = 0;
dev->sectors = 0;
+ dev->multi_count = 0;
/*
* common ATA, ATAPI feature tests
@@ -2426,8 +2427,15 @@
dev->n_sectors = ata_id_n_sectors(id);
- if (dev->id[59] & 0x100)
- dev->multi_count = dev->id[59] & 0xff;
+ /* get current R/W Multiple count setting */
+ if ((dev->id[47] >> 8) == 0x80 && (dev->id[59] & 0x100)) {
+ unsigned int max = dev->id[47] & 0xff;
+ unsigned int cnt = dev->id[59] & 0xff;
+ /* only recognize/allow powers of two here */
+ if (is_power_of_2(max) && is_power_of_2(cnt))
+ if (cnt <= max)
+ dev->multi_count = cnt;
+ }
if (ata_id_has_lba(id)) {
const char *lba_desc;
--- libata-dev/drivers/ata/libata-core.c.orig 2009-03-18 11:08:27.000000000 -0400
+++ libata-dev/drivers/ata/libata-core.c 2009-03-19 13:26:37.000000000 -0400
@@ -57,6 +57,7 @@
#include <linux/scatterlist.h>
#include <linux/io.h>
#include <linux/async.h>
+#include <linux/log2.h>
#include <scsi/scsi.h>
#include <scsi/scsi_cmnd.h>
#include <scsi/scsi_host.h>
@@ -2389,6 +2390,7 @@
dev->cylinders = 0;
dev->heads = 0;
dev->sectors = 0;
+ dev->multi_count = 0;
/*
* common ATA, ATAPI feature tests
@@ -2426,8 +2428,15 @@
dev->n_sectors = ata_id_n_sectors(id);
- if (dev->id[59] & 0x100)
- dev->multi_count = dev->id[59] & 0xff;
+ /* get current R/W Multiple count setting */
+ if ((dev->id[47] >> 8) == 0x80 && (dev->id[59] & 0x100)) {
+ unsigned int max = dev->id[47] & 0xff;
+ unsigned int cnt = dev->id[59] & 0xff;
+ /* only recognize/allow powers of two here */
+ if (is_power_of_2(max) && is_power_of_2(cnt))
+ if (cnt <= max)
+ dev->multi_count = cnt;
+ }
if (ata_id_has_lba(id)) {
const char *lba_desc;
next prev parent reply other threads:[~2009-03-19 17:30 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-18 14:26 [PATCH] libata-core Use more robust parsing for multi_count Mark Lord
2009-03-18 14:32 ` Alan Cox
2009-03-18 15:06 ` Mark Lord
2009-03-18 15:13 ` Mark Lord
2009-03-18 17:09 ` Alan Cox
2009-03-18 15:58 ` Mark Lord
2009-03-18 16:18 ` [PATCH] libata-core More robust parsing for multi_count(v3) Mark Lord
2009-03-18 16:24 ` Mark Lord
2009-03-19 0:23 ` Tejun Heo
2009-03-19 0:25 ` Tejun Heo
2009-03-19 17:30 ` Mark Lord [this message]
2009-03-19 17:32 ` [PATCH] libata-core More robust parsing for multi_count(v5) Mark Lord
2009-03-19 23:33 ` Tejun Heo
2009-03-20 3:37 ` Mark Lord
2009-03-20 13:13 ` Mark Lord
2009-03-20 13:14 ` Mark Lord
2009-03-20 14:07 ` Alan Cox
2009-03-20 15:36 ` Mark Lord
2009-03-20 23:14 ` Tejun Heo
2009-03-21 0:54 ` Jeff Garzik
2009-03-21 2:17 ` Tejun Heo
2009-03-21 13:54 ` Mark Lord
2009-03-21 14:02 ` Alan Cox
2009-03-21 14:59 ` Mark Lord
2009-03-20 13:38 ` Alan Cox
2009-04-12 15:10 ` Mark Lord
2009-04-12 15:18 ` Alan Cox
2009-04-12 15:31 ` Jeff Garzik
2009-03-25 2:40 ` Jeff Garzik
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=49C28133.8050401@rtr.ca \
--to=liml@rtr.ca \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=jgarzik@pobox.com \
--cc=linux-ide@vger.kernel.org \
--cc=tj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).