From baf6722aa0cbc5381f11520eb661be71b3ac379e Mon Sep 17 00:00:00 2001 From: Chuhong Yuan Date: Tue, 23 Jul 2019 19:49:52 +0800 Subject: [PATCH 01/10] ide: Use dev_get_drvdata where possible Instead of using to_pci_dev + pci_get_drvdata, use dev_get_drvdata to make code simpler. Signed-off-by: Chuhong Yuan Signed-off-by: David S. Miller --- drivers/ide/siimage.c | 3 +-- drivers/ide/via82cxxx.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c index 57eea5a9047f..c4b20f350b84 100644 --- a/drivers/ide/siimage.c +++ b/drivers/ide/siimage.c @@ -648,8 +648,7 @@ static void sil_quirkproc(ide_drive_t *drive) static void init_iops_siimage(ide_hwif_t *hwif) { - struct pci_dev *dev = to_pci_dev(hwif->dev); - struct ide_host *host = pci_get_drvdata(dev); + struct ide_host *host = dev_get_drvdata(hwif->dev); hwif->hwif_data = NULL; diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c index 977cb00398b0..63a3aca506fc 100644 --- a/drivers/ide/via82cxxx.c +++ b/drivers/ide/via82cxxx.c @@ -175,8 +175,7 @@ static void via_set_speed(ide_hwif_t *hwif, u8 dn, struct ide_timing *timing) static void via_set_drive(ide_hwif_t *hwif, ide_drive_t *drive) { ide_drive_t *peer = ide_get_pair_dev(drive); - struct pci_dev *dev = to_pci_dev(hwif->dev); - struct ide_host *host = pci_get_drvdata(dev); + struct ide_host *host = dev_get_drvdata(hwif->dev); struct via82cxxx_dev *vdev = host->host_priv; struct ide_timing t, p; unsigned int T, UT; From 044b1a933108bc1122fda85c711ed5a93bc5ecd5 Mon Sep 17 00:00:00 2001 From: Christophe JAILLET Date: Thu, 25 Jul 2019 00:01:45 +0200 Subject: [PATCH 02/10] ide: tx4939ide: Fix the name used in a 'devm_request_mem_region()' call This should be "tx4939ide" instead of "tx4938ide", but here MODNAME is even better. Signed-off-by: Christophe JAILLET Signed-off-by: David S. Miller --- drivers/ide/tx4939ide.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/ide/tx4939ide.c b/drivers/ide/tx4939ide.c index 88d132edc4e3..079b271dd5a7 100644 --- a/drivers/ide/tx4939ide.c +++ b/drivers/ide/tx4939ide.c @@ -549,7 +549,7 @@ static int __init tx4939ide_probe(struct platform_device *pdev) return -ENODEV; if (!devm_request_mem_region(&pdev->dev, res->start, - resource_size(res), "tx4938ide")) + resource_size(res), MODNAME)) return -EBUSY; mapbase = (unsigned long)devm_ioremap(&pdev->dev, res->start, resource_size(res)); From 77df3500a75d946b3f60112a5207900e29e13b68 Mon Sep 17 00:00:00 2001 From: Guoqing Jiang Date: Thu, 26 Sep 2019 15:13:44 +0200 Subject: [PATCH 03/10] ide: remove unnecessary touch_softlockup_watchdog Call touch_softlockup_watchdog before touch_nmi_watchdog is not needed, since touch_softlockup_watchdog is called inside touch_nmi_watchdog. Signed-off-by: Guoqing Jiang Signed-off-by: David S. Miller --- drivers/ide/ide-iops.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/ide/ide-iops.c b/drivers/ide/ide-iops.c index d1445d74e9c3..f2be127ee96e 100644 --- a/drivers/ide/ide-iops.c +++ b/drivers/ide/ide-iops.c @@ -530,7 +530,6 @@ int ide_wait_not_busy(ide_hwif_t *hwif, unsigned long timeout) */ if (stat == 0xff) return -ENODEV; - touch_softlockup_watchdog(); touch_nmi_watchdog(); } return -EBUSY; From 98949a1946d70771789def0c9dbc239497f9f138 Mon Sep 17 00:00:00 2001 From: Wang Hai Date: Sat, 26 Oct 2019 09:57:38 +0800 Subject: [PATCH 04/10] ide: remove set but not used variable 'hwif' Fix the following gcc warning: drivers/ide/pmac.c: In function pmac_ide_setup_device: drivers/ide/pmac.c:1027:14: warning: variable hwif set but not used [-Wunused-but-set-variable] Fixes: d58b0c39e32f ("powerpc/macio: Rework hotplug media bay support") Reported-by: Hulk Robot Signed-off-by: Wang Hai Signed-off-by: David S. Miller --- drivers/ide/pmac.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/ide/pmac.c b/drivers/ide/pmac.c index b5647e34e74e..ea0b064b5f56 100644 --- a/drivers/ide/pmac.c +++ b/drivers/ide/pmac.c @@ -1019,7 +1019,6 @@ static int pmac_ide_setup_device(pmac_ide_hwif_t *pmif, struct ide_hw *hw) struct device_node *np = pmif->node; const int *bidp; struct ide_host *host; - ide_hwif_t *hwif; struct ide_hw *hws[] = { hw }; struct ide_port_info d = pmac_port_info; int rc; @@ -1075,7 +1074,7 @@ static int pmac_ide_setup_device(pmac_ide_hwif_t *pmif, struct ide_hw *hw) rc = -ENOMEM; goto bail; } - hwif = pmif->hwif = host->ports[0]; + pmif->hwif = host->ports[0]; if (on_media_bay(pmif)) { /* Fixup bus ID for media bay */ From 1011b6908a74755b2385d4cc569e9d061532ad53 Mon Sep 17 00:00:00 2001 From: Krzysztof Kozlowski Date: Sat, 4 Jan 2020 15:33:47 +0100 Subject: [PATCH 05/10] ide: ht6560b: Fix cast to pointer from integer of different size MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Integer passed as pointer to drvdata should be cast to unsigned long to avoid warning (compile testing on alpha architecture): drivers/ide/ht6560b.c: In function ‘ht6560b_init_dev’: drivers/ide/ht6560b.c:318:27: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] Signed-off-by: Krzysztof Kozlowski Signed-off-by: David S. Miller --- drivers/ide/ht6560b.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/ide/ht6560b.c b/drivers/ide/ht6560b.c index 0dae65ac7d6d..743bc3693ac8 100644 --- a/drivers/ide/ht6560b.c +++ b/drivers/ide/ht6560b.c @@ -310,7 +310,7 @@ static void __init ht6560b_init_dev(ide_drive_t *drive) { ide_hwif_t *hwif = drive->hwif; /* Setting default configurations for drives. */ - int t = (HT_CONFIG_DEFAULT << 8) | HT_TIMING_DEFAULT; + unsigned long t = (HT_CONFIG_DEFAULT << 8) | HT_TIMING_DEFAULT; if (hwif->channel) t |= (HT_SECONDARY_IF << 8); From 5b10c23e180950c71703e02efbf998ed25bdc682 Mon Sep 17 00:00:00 2001 From: Krzysztof Kozlowski Date: Sat, 4 Jan 2020 15:33:48 +0100 Subject: [PATCH 06/10] ide: qd65xx: Fix cast to pointer from integer of different size MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Integer passed as pointer to drvdata should be cast to unsigned long to avoid warning (compile testing on alpha architecture): drivers/ide/qd65xx.c: In function ‘qd6580_init_dev’: drivers/ide/qd65xx.c:312:27: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] Signed-off-by: Krzysztof Kozlowski Signed-off-by: David S. Miller --- drivers/ide/qd65xx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/ide/qd65xx.c b/drivers/ide/qd65xx.c index 6ce318ebd0cc..ab79b6289464 100644 --- a/drivers/ide/qd65xx.c +++ b/drivers/ide/qd65xx.c @@ -299,7 +299,7 @@ static void __init qd6500_init_dev(ide_drive_t *drive) static void __init qd6580_init_dev(ide_drive_t *drive) { ide_hwif_t *hwif = drive->hwif; - u16 t1, t2; + unsigned long t1, t2; u8 base = (hwif->config_data & 0xff00) >> 8; u8 config = QD_CONFIG(hwif); From 0fdeae5036086aa214a45e598c079a3334bc15c3 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 5 Jan 2020 01:40:11 +0900 Subject: [PATCH 07/10] ide: remove unneeded header include path to drivers/ide I can build drivers/ide/ without this. Signed-off-by: Masahiro Yamada Signed-off-by: David S. Miller --- drivers/ide/Makefile | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/ide/Makefile b/drivers/ide/Makefile index 9f617a77970f..d7c848580147 100644 --- a/drivers/ide/Makefile +++ b/drivers/ide/Makefile @@ -3,8 +3,6 @@ # link order is important here # -ccflags-y := -Idrivers/ide - ide-core-y += ide.o ide-ioctls.o ide-io.o ide-iops.o ide-lib.o ide-probe.o \ ide-taskfile.o ide-pm.o ide-park.o ide-sysfs.o ide-devsets.o \ ide-io-std.o ide-eh.o From 117fcc3053606d8db5cef8821dca15022ae578bb Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Tue, 7 Jan 2020 16:04:41 +0300 Subject: [PATCH 08/10] cmd64x: potential buffer overflow in cmd64x_program_timings() The "drive->dn" value is a u8 and it is controlled by root only, but it could be out of bounds here so let's check. Signed-off-by: Dan Carpenter Signed-off-by: David S. Miller --- drivers/ide/cmd64x.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c index a1898e11b04e..943bf944bf72 100644 --- a/drivers/ide/cmd64x.c +++ b/drivers/ide/cmd64x.c @@ -66,6 +66,9 @@ static void cmd64x_program_timings(ide_drive_t *drive, u8 mode) struct ide_timing t; u8 arttim = 0; + if (drive->dn >= ARRAY_SIZE(drwtim_regs)) + return; + ide_timing_compute(drive, mode, &t, T, 0); /* From ce1f31b4c0b9551dd51874dd5364654ed4ca13ae Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Tue, 7 Jan 2020 16:06:07 +0300 Subject: [PATCH 09/10] ide: serverworks: potential overflow in svwks_set_pio_mode() The "drive->dn" variable is a u8 controlled by root. Signed-off-by: Dan Carpenter Signed-off-by: David S. Miller --- drivers/ide/serverworks.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c index ac6fc3fffa0d..458e72e034b0 100644 --- a/drivers/ide/serverworks.c +++ b/drivers/ide/serverworks.c @@ -115,6 +115,9 @@ static void svwks_set_pio_mode(ide_hwif_t *hwif, ide_drive_t *drive) struct pci_dev *dev = to_pci_dev(hwif->dev); const u8 pio = drive->pio_mode - XFER_PIO_0; + if (drive->dn >= ARRAY_SIZE(drive_pci)) + return; + pci_write_config_byte(dev, drive_pci[drive->dn], pio_modes[pio]); if (svwks_csb_check(dev)) { @@ -141,6 +144,9 @@ static void svwks_set_dma_mode(ide_hwif_t *hwif, ide_drive_t *drive) u8 ultra_enable = 0, ultra_timing = 0, dma_timing = 0; + if (drive->dn >= ARRAY_SIZE(drive_pci2)) + return; + pci_read_config_byte(dev, (0x56|hwif->channel), &ultra_timing); pci_read_config_byte(dev, 0x54, &ultra_enable); From 2fd3c5c617937cde5aafa48db4f4056e1f705987 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Tue, 21 Jan 2020 16:06:42 +0300 Subject: [PATCH 10/10] ide: make drive->dn read only The IDE core always sets ->dn correctly so changing it is never required. Setting it to a different value than assigned by IDE core is very likely to result in data corruption (due to wrong transfer timings being set on the controller etc.) Signed-off-by: Dan Carpenter Acked-by: Bartlomiej Zolnierkiewicz Tested-by: Bartlomiej Zolnierkiewicz Signed-off-by: David S. Miller --- drivers/ide/ide-proc.c | 2 +- include/linux/ide.h | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/ide/ide-proc.c b/drivers/ide/ide-proc.c index 0363d73b0be0..e73016cbd406 100644 --- a/drivers/ide/ide-proc.c +++ b/drivers/ide/ide-proc.c @@ -206,7 +206,7 @@ static int set_xfer_rate (ide_drive_t *drive, int arg) ide_devset_rw(current_speed, xfer_rate); ide_devset_rw_field(init_speed, init_speed); ide_devset_rw_flag(nice1, IDE_DFLAG_NICE1); -ide_devset_rw_field(number, dn); +ide_devset_ro_field(number, dn); static const struct ide_proc_devset ide_generic_settings[] = { IDE_PROC_DEVSET(current_speed, 0, 70), diff --git a/include/linux/ide.h b/include/linux/ide.h index 46b771d6999e..25046ffa5a4a 100644 --- a/include/linux/ide.h +++ b/include/linux/ide.h @@ -943,6 +943,10 @@ ide_devset_get(_name, _field); \ ide_devset_set(_name, _field); \ IDE_DEVSET(_name, DS_SYNC, get_##_name, set_##_name) +#define ide_devset_ro_field(_name, _field) \ +ide_devset_get(_name, _field); \ +IDE_DEVSET(_name, 0, get_##_name, NULL) + #define ide_devset_rw_flag(_name, _field) \ ide_devset_get_flag(_name, _field); \ ide_devset_set_flag(_name, _field); \