struct ds2404 *chip;
        int retval = -EBUSY;
 
-       chip = kzalloc(sizeof(struct ds2404), GFP_KERNEL);
+       chip = devm_kzalloc(&pdev->dev, sizeof(struct ds2404), GFP_KERNEL);
        if (!chip)
                return -ENOMEM;
 
 
        platform_set_drvdata(pdev, chip);
 
-       chip->rtc = rtc_device_register("ds2404",
-                               &pdev->dev, &ds2404_rtc_ops, THIS_MODULE);
+       chip->rtc = devm_rtc_device_register(&pdev->dev, "ds2404",
+                                       &ds2404_rtc_ops, THIS_MODULE);
        if (IS_ERR(chip->rtc)) {
                retval = PTR_ERR(chip->rtc);
                goto err_io;
 err_io:
        chip->ops->unmap_io(chip);
 err_chip:
-       kfree(chip);
        return retval;
 }
 
 static int rtc_remove(struct platform_device *dev)
 {
        struct ds2404 *chip = platform_get_drvdata(dev);
-       struct rtc_device *rtc = chip->rtc;
-
-       if (rtc)
-               rtc_device_unregister(rtc);
 
        chip->ops->unmap_io(chip);
-       kfree(chip);
 
        return 0;
 }