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

rtc: ep93xx: Fix 'rtc' may be used uninitialized warning

commit 92d921c5d "rtc: ep93xx: Initialize drvdata before registering device"
ensures the drvdata is initialized prior to registering the rtc device.
But it set the drvdata to an uninitialized pointer.
Thus calling platform_get_drvdata in ep93xx_rtc_remove does not get correct address.

This patch fixes below warning by adding struct rtc_device *rtc to struct ep93xx_rtc.
Then set platform drvdata to ep93xx_rtc instead of rtc.

CC drivers/rtc/rtc-ep93xx.o
drivers/rtc/rtc-ep93xx.c: In function 'ep93xx_rtc_probe':
drivers/rtc/rtc-ep93xx.c:154: warning: 'rtc' may be used uninitialized in this function

Signed-off-by: Axel Lin <axel.lin@gmail.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>

authored by

Axel Lin and committed by
John Stultz
bf6ed027 322a8b03

+8 -8
+8 -8
drivers/rtc/rtc-ep93xx.c
··· 36 36 */ 37 37 struct ep93xx_rtc { 38 38 void __iomem *mmio_base; 39 + struct rtc_device *rtc; 39 40 }; 40 41 41 42 static int ep93xx_rtc_get_swcomp(struct device *dev, unsigned short *preload, ··· 131 130 { 132 131 struct ep93xx_rtc *ep93xx_rtc; 133 132 struct resource *res; 134 - struct rtc_device *rtc; 135 133 int err; 136 134 137 135 ep93xx_rtc = devm_kzalloc(&pdev->dev, sizeof(*ep93xx_rtc), GFP_KERNEL); ··· 151 151 return -ENXIO; 152 152 153 153 pdev->dev.platform_data = ep93xx_rtc; 154 - platform_set_drvdata(pdev, rtc); 154 + platform_set_drvdata(pdev, ep93xx_rtc); 155 155 156 - rtc = rtc_device_register(pdev->name, 156 + ep93xx_rtc->rtc = rtc_device_register(pdev->name, 157 157 &pdev->dev, &ep93xx_rtc_ops, THIS_MODULE); 158 - if (IS_ERR(rtc)) { 159 - err = PTR_ERR(rtc); 158 + if (IS_ERR(ep93xx_rtc->rtc)) { 159 + err = PTR_ERR(ep93xx_rtc->rtc); 160 160 goto exit; 161 161 } 162 162 ··· 167 167 return 0; 168 168 169 169 fail: 170 - rtc_device_unregister(rtc); 170 + rtc_device_unregister(ep93xx_rtc->rtc); 171 171 exit: 172 172 platform_set_drvdata(pdev, NULL); 173 173 pdev->dev.platform_data = NULL; ··· 176 176 177 177 static int __exit ep93xx_rtc_remove(struct platform_device *pdev) 178 178 { 179 - struct rtc_device *rtc = platform_get_drvdata(pdev); 179 + struct ep93xx_rtc *ep93xx_rtc = platform_get_drvdata(pdev); 180 180 181 181 sysfs_remove_group(&pdev->dev.kobj, &ep93xx_rtc_sysfs_files); 182 182 platform_set_drvdata(pdev, NULL); 183 - rtc_device_unregister(rtc); 183 + rtc_device_unregister(ep93xx_rtc->rtc); 184 184 pdev->dev.platform_data = NULL; 185 185 186 186 return 0;