Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usb: ehci-fsl: Fix use of private data to avoid -Wflex-array-member-not-at-end warning

In the course of fixing up the usages of flexible arrays, Gustavo
submitted a patch updating the ehci-fsl driver. However, the patch
was wrong because the driver was using the .priv member of the
ehci_hcd structure incorrectly. The private data is not supposed to
be a wrapper containing the ehci_hcd structure; it is supposed to be a
sub-structure stored in the .priv member.

Fix the problem by replacing the ehci_fsl structure with
ehci_fsl_priv, containing only the private data, along with a suitable
conversion macro for accessing it. This removes the problem of having
data follow a flexible array member.

Reported-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Link: https://lore.kernel.org/linux-usb/Z-R9BcnSzrRv5FX_@kspp/
Reviewed-by: Kees Cook <kees@kernel.org>
Link: https://lore.kernel.org/r/8139e4cc-4e5c-40e2-9c4b-717ad3215868@rowland.harvard.edu
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Alan Stern and committed by
Greg Kroah-Hartman
54f9823b 387602d8

+8 -17
+8 -17
drivers/usb/host/ehci-fsl.c
··· 410 410 return retval; 411 411 } 412 412 413 - struct ehci_fsl { 414 - struct ehci_hcd ehci; 415 - 416 - #ifdef CONFIG_PM 413 + struct ehci_fsl_priv { 417 414 /* Saved USB PHY settings, need to restore after deep sleep. */ 418 415 u32 usb_ctrl; 419 - #endif 420 416 }; 417 + 418 + #define hcd_to_ehci_fsl_priv(h) ((struct ehci_fsl_priv *) hcd_to_ehci(h)->priv) 421 419 422 420 #ifdef CONFIG_PM 423 421 ··· 564 566 } 565 567 #endif /* CONFIG_PPC_MPC512x */ 566 568 567 - static struct ehci_fsl *hcd_to_ehci_fsl(struct usb_hcd *hcd) 568 - { 569 - struct ehci_hcd *ehci = hcd_to_ehci(hcd); 570 - 571 - return container_of(ehci, struct ehci_fsl, ehci); 572 - } 573 - 574 569 static int ehci_fsl_drv_suspend(struct device *dev) 575 570 { 576 571 struct usb_hcd *hcd = dev_get_drvdata(dev); 577 - struct ehci_fsl *ehci_fsl = hcd_to_ehci_fsl(hcd); 572 + struct ehci_fsl_priv *priv = hcd_to_ehci_fsl_priv(hcd); 578 573 void __iomem *non_ehci = hcd->regs; 579 574 580 575 if (of_device_is_compatible(dev->parent->of_node, ··· 580 589 if (!fsl_deep_sleep()) 581 590 return 0; 582 591 583 - ehci_fsl->usb_ctrl = ioread32be(non_ehci + FSL_SOC_USB_CTRL); 592 + priv->usb_ctrl = ioread32be(non_ehci + FSL_SOC_USB_CTRL); 584 593 return 0; 585 594 } 586 595 587 596 static int ehci_fsl_drv_resume(struct device *dev) 588 597 { 589 598 struct usb_hcd *hcd = dev_get_drvdata(dev); 590 - struct ehci_fsl *ehci_fsl = hcd_to_ehci_fsl(hcd); 599 + struct ehci_fsl_priv *priv = hcd_to_ehci_fsl_priv(hcd); 591 600 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 592 601 void __iomem *non_ehci = hcd->regs; 593 602 ··· 603 612 usb_root_hub_lost_power(hcd->self.root_hub); 604 613 605 614 /* Restore USB PHY settings and enable the controller. */ 606 - iowrite32be(ehci_fsl->usb_ctrl, non_ehci + FSL_SOC_USB_CTRL); 615 + iowrite32be(priv->usb_ctrl, non_ehci + FSL_SOC_USB_CTRL); 607 616 608 617 ehci_reset(ehci); 609 618 ehci_fsl_reinit(ehci); ··· 662 671 #endif /* CONFIG_USB_OTG */ 663 672 664 673 static const struct ehci_driver_overrides ehci_fsl_overrides __initconst = { 665 - .extra_priv_size = sizeof(struct ehci_fsl), 674 + .extra_priv_size = sizeof(struct ehci_fsl_priv), 666 675 .reset = ehci_fsl_setup, 667 676 }; 668 677