Skip to content

Commit 45c4c5a

Browse files
floatiousdamien-lemoal
authored andcommitted
ata: libata: Add support to parse equal sign in libata.force
Currently, no libata.force parameter supports an arbitrary value. All allowed values, e.g. udma/16, udma/25, udma/33, udma/44, udma/66, udma/100, udma/133 have hardcoded entries in the force_tbl table. Add code to allow a libata.force param with the format libata.force=param=param_value, where param_value can be an arbitrary value. This code will be used in a follow up commit. Signed-off-by: Niklas Cassel <cassel@kernel.org> Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com> Reviewed-by: Damien Le Moal <dlemoal@kernel.org> Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
1 parent dfd9751 commit 45c4c5a

1 file changed

Lines changed: 36 additions & 2 deletions

File tree

drivers/ata/libata-core.c

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6490,6 +6490,13 @@ EXPORT_SYMBOL_GPL(ata_platform_remove_one);
64906490
{ "no" #name, .quirk_on = (flag) }, \
64916491
{ #name, .quirk_off = (flag) }
64926492

6493+
/*
6494+
* If the ata_force_param struct member 'name' ends with '=', then the value
6495+
* after the equal sign will be parsed as an u64, and will be saved in the
6496+
* ata_force_param struct member 'value'. This works because each libata.force
6497+
* entry (struct ata_force_ent) is separated by commas, so each entry represents
6498+
* a single quirk, and can thus only have a single value.
6499+
*/
64936500
static const struct ata_force_param force_tbl[] __initconst = {
64946501
force_cbl(40c, ATA_CBL_PATA40),
64956502
force_cbl(80c, ATA_CBL_PATA80),
@@ -6577,8 +6584,9 @@ static int __init ata_parse_force_one(char **cur,
65776584
const char **reason)
65786585
{
65796586
char *start = *cur, *p = *cur;
6580-
char *id, *val, *endp;
6587+
char *id, *val, *endp, *equalsign, *char_after_equalsign;
65816588
const struct ata_force_param *match_fp = NULL;
6589+
u64 val_after_equalsign;
65826590
int nr_matches = 0, i;
65836591

65846592
/* find where this param ends and update *cur */
@@ -6621,10 +6629,36 @@ static int __init ata_parse_force_one(char **cur,
66216629
}
66226630

66236631
parse_val:
6624-
/* parse val, allow shortcuts so that both 1.5 and 1.5Gbps work */
6632+
equalsign = strchr(val, '=');
6633+
if (equalsign) {
6634+
char_after_equalsign = equalsign + 1;
6635+
if (!strlen(char_after_equalsign) ||
6636+
kstrtoull(char_after_equalsign, 10, &val_after_equalsign)) {
6637+
*reason = "invalid value after equal sign";
6638+
return -EINVAL;
6639+
}
6640+
}
6641+
6642+
/* Parse the parameter value. */
66256643
for (i = 0; i < ARRAY_SIZE(force_tbl); i++) {
66266644
const struct ata_force_param *fp = &force_tbl[i];
66276645

6646+
/*
6647+
* If val contains equal sign, match has to be exact, i.e.
6648+
* shortcuts are not supported.
6649+
*/
6650+
if (equalsign &&
6651+
(strncasecmp(val, fp->name,
6652+
char_after_equalsign - val) == 0)) {
6653+
force_ent->param = *fp;
6654+
force_ent->param.value = val_after_equalsign;
6655+
return 0;
6656+
}
6657+
6658+
/*
6659+
* If val does not contain equal sign, allow shortcuts so that
6660+
* both 1.5 and 1.5Gbps work.
6661+
*/
66286662
if (strncasecmp(val, fp->name, strlen(val)))
66296663
continue;
66306664

0 commit comments

Comments
 (0)