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

drm/shmobile: Use devm_* managed functions

This simplifies cleanup paths and fixes a probe time crash in the error
path when trying to cleanup mode setting before it was initialized.

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>

+10 -25
+9 -19
drivers/gpu/drm/shmobile/shmob_drm_drv.c
··· 90 90 return -EINVAL; 91 91 } 92 92 93 - clk = clk_get(sdev->dev, clkname); 93 + clk = devm_clk_get(sdev->dev, clkname); 94 94 if (IS_ERR(clk)) { 95 95 dev_err(sdev->dev, "cannot get dot clock %s\n", clkname); 96 96 return PTR_ERR(clk); ··· 106 106 107 107 static int shmob_drm_unload(struct drm_device *dev) 108 108 { 109 - struct shmob_drm_device *sdev = dev->dev_private; 110 - 111 109 drm_kms_helper_poll_fini(dev); 112 110 drm_mode_config_cleanup(dev); 113 111 drm_vblank_cleanup(dev); 114 112 drm_irq_uninstall(dev); 115 113 116 - if (sdev->clock) 117 - clk_put(sdev->clock); 118 - 119 - if (sdev->mmio) 120 - iounmap(sdev->mmio); 121 - 122 114 dev->dev_private = NULL; 123 - kfree(sdev); 124 115 125 116 return 0; 126 117 } ··· 130 139 return -EINVAL; 131 140 } 132 141 133 - sdev = kzalloc(sizeof(*sdev), GFP_KERNEL); 142 + sdev = devm_kzalloc(&pdev->dev, sizeof(*sdev), GFP_KERNEL); 134 143 if (sdev == NULL) { 135 144 dev_err(dev->dev, "failed to allocate private data\n"); 136 145 return -ENOMEM; ··· 147 156 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 148 157 if (res == NULL) { 149 158 dev_err(&pdev->dev, "failed to get memory resource\n"); 150 - ret = -EINVAL; 151 - goto done; 159 + return -EINVAL; 152 160 } 153 161 154 - sdev->mmio = ioremap_nocache(res->start, resource_size(res)); 162 + sdev->mmio = devm_ioremap_nocache(&pdev->dev, res->start, 163 + resource_size(res)); 155 164 if (sdev->mmio == NULL) { 156 165 dev_err(&pdev->dev, "failed to remap memory resource\n"); 157 - ret = -ENOMEM; 158 - goto done; 166 + return -ENOMEM; 159 167 } 160 168 161 169 ret = shmob_drm_setup_clocks(sdev, pdata->clk_source); 162 170 if (ret < 0) 163 - goto done; 171 + return ret; 164 172 165 173 ret = shmob_drm_init_interface(sdev); 166 174 if (ret < 0) 167 - goto done; 175 + return ret; 168 176 169 177 ret = shmob_drm_modeset_init(sdev); 170 178 if (ret < 0) { 171 179 dev_err(&pdev->dev, "failed to initialize mode setting\n"); 172 - goto done; 180 + return ret; 173 181 } 174 182 175 183 for (i = 0; i < 4; ++i) {
+1 -6
drivers/gpu/drm/shmobile/shmob_drm_plane.c
··· 221 221 222 222 static void shmob_drm_plane_destroy(struct drm_plane *plane) 223 223 { 224 - struct shmob_drm_plane *splane = to_shmob_plane(plane); 225 - 226 224 shmob_drm_plane_disable(plane); 227 225 drm_plane_cleanup(plane); 228 - kfree(splane); 229 226 } 230 227 231 228 static const struct drm_plane_funcs shmob_drm_plane_funcs = { ··· 248 251 struct shmob_drm_plane *splane; 249 252 int ret; 250 253 251 - splane = kzalloc(sizeof(*splane), GFP_KERNEL); 254 + splane = devm_kzalloc(sdev->dev, sizeof(*splane), GFP_KERNEL); 252 255 if (splane == NULL) 253 256 return -ENOMEM; 254 257 ··· 258 261 ret = drm_plane_init(sdev->ddev, &splane->plane, 1, 259 262 &shmob_drm_plane_funcs, formats, 260 263 ARRAY_SIZE(formats), false); 261 - if (ret < 0) 262 - kfree(splane); 263 264 264 265 return ret; 265 266 }