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

regulator: core: Use DEVICE_ATTR_RO macro

Use DEVICE_ATTR_RO() helper instead of plain DEVICE_ATTR(),
which makes the code a bit shorter and easier to read.

Signed-off-by: YueHaibing <yuehaibing@huawei.com>
Link: https://lore.kernel.org/r/20210529115226.25376-1-yuehaibing@huawei.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

YueHaibing and committed by
Mark Brown
a277a262 96ec5afe

+60 -70
+60 -70
drivers/regulator/core.c
··· 591 591 return rstate; 592 592 } 593 593 594 - static ssize_t regulator_uV_show(struct device *dev, 595 - struct device_attribute *attr, char *buf) 594 + static ssize_t microvolts_show(struct device *dev, 595 + struct device_attribute *attr, char *buf) 596 596 { 597 597 struct regulator_dev *rdev = dev_get_drvdata(dev); 598 598 int uV; ··· 605 605 return uV; 606 606 return sprintf(buf, "%d\n", uV); 607 607 } 608 - static DEVICE_ATTR(microvolts, 0444, regulator_uV_show, NULL); 608 + static DEVICE_ATTR_RO(microvolts); 609 609 610 - static ssize_t regulator_uA_show(struct device *dev, 611 - struct device_attribute *attr, char *buf) 610 + static ssize_t microamps_show(struct device *dev, 611 + struct device_attribute *attr, char *buf) 612 612 { 613 613 struct regulator_dev *rdev = dev_get_drvdata(dev); 614 614 615 615 return sprintf(buf, "%d\n", _regulator_get_current_limit(rdev)); 616 616 } 617 - static DEVICE_ATTR(microamps, 0444, regulator_uA_show, NULL); 617 + static DEVICE_ATTR_RO(microamps); 618 618 619 619 static ssize_t name_show(struct device *dev, struct device_attribute *attr, 620 620 char *buf) ··· 645 645 return sprintf(buf, "%s\n", regulator_opmode_to_str(mode)); 646 646 } 647 647 648 - static ssize_t regulator_opmode_show(struct device *dev, 649 - struct device_attribute *attr, char *buf) 648 + static ssize_t opmode_show(struct device *dev, 649 + struct device_attribute *attr, char *buf) 650 650 { 651 651 struct regulator_dev *rdev = dev_get_drvdata(dev); 652 652 653 653 return regulator_print_opmode(buf, _regulator_get_mode(rdev)); 654 654 } 655 - static DEVICE_ATTR(opmode, 0444, regulator_opmode_show, NULL); 655 + static DEVICE_ATTR_RO(opmode); 656 656 657 657 static ssize_t regulator_print_state(char *buf, int state) 658 658 { ··· 664 664 return sprintf(buf, "unknown\n"); 665 665 } 666 666 667 - static ssize_t regulator_state_show(struct device *dev, 668 - struct device_attribute *attr, char *buf) 667 + static ssize_t state_show(struct device *dev, 668 + struct device_attribute *attr, char *buf) 669 669 { 670 670 struct regulator_dev *rdev = dev_get_drvdata(dev); 671 671 ssize_t ret; ··· 676 676 677 677 return ret; 678 678 } 679 - static DEVICE_ATTR(state, 0444, regulator_state_show, NULL); 679 + static DEVICE_ATTR_RO(state); 680 680 681 - static ssize_t regulator_status_show(struct device *dev, 682 - struct device_attribute *attr, char *buf) 681 + static ssize_t status_show(struct device *dev, 682 + struct device_attribute *attr, char *buf) 683 683 { 684 684 struct regulator_dev *rdev = dev_get_drvdata(dev); 685 685 int status; ··· 723 723 724 724 return sprintf(buf, "%s\n", label); 725 725 } 726 - static DEVICE_ATTR(status, 0444, regulator_status_show, NULL); 726 + static DEVICE_ATTR_RO(status); 727 727 728 - static ssize_t regulator_min_uA_show(struct device *dev, 729 - struct device_attribute *attr, char *buf) 728 + static ssize_t min_microamps_show(struct device *dev, 729 + struct device_attribute *attr, char *buf) 730 730 { 731 731 struct regulator_dev *rdev = dev_get_drvdata(dev); 732 732 ··· 735 735 736 736 return sprintf(buf, "%d\n", rdev->constraints->min_uA); 737 737 } 738 - static DEVICE_ATTR(min_microamps, 0444, regulator_min_uA_show, NULL); 738 + static DEVICE_ATTR_RO(min_microamps); 739 739 740 - static ssize_t regulator_max_uA_show(struct device *dev, 741 - struct device_attribute *attr, char *buf) 740 + static ssize_t max_microamps_show(struct device *dev, 741 + struct device_attribute *attr, char *buf) 742 742 { 743 743 struct regulator_dev *rdev = dev_get_drvdata(dev); 744 744 ··· 747 747 748 748 return sprintf(buf, "%d\n", rdev->constraints->max_uA); 749 749 } 750 - static DEVICE_ATTR(max_microamps, 0444, regulator_max_uA_show, NULL); 750 + static DEVICE_ATTR_RO(max_microamps); 751 751 752 - static ssize_t regulator_min_uV_show(struct device *dev, 753 - struct device_attribute *attr, char *buf) 752 + static ssize_t min_microvolts_show(struct device *dev, 753 + struct device_attribute *attr, char *buf) 754 754 { 755 755 struct regulator_dev *rdev = dev_get_drvdata(dev); 756 756 ··· 759 759 760 760 return sprintf(buf, "%d\n", rdev->constraints->min_uV); 761 761 } 762 - static DEVICE_ATTR(min_microvolts, 0444, regulator_min_uV_show, NULL); 762 + static DEVICE_ATTR_RO(min_microvolts); 763 763 764 - static ssize_t regulator_max_uV_show(struct device *dev, 765 - struct device_attribute *attr, char *buf) 764 + static ssize_t max_microvolts_show(struct device *dev, 765 + struct device_attribute *attr, char *buf) 766 766 { 767 767 struct regulator_dev *rdev = dev_get_drvdata(dev); 768 768 ··· 771 771 772 772 return sprintf(buf, "%d\n", rdev->constraints->max_uV); 773 773 } 774 - static DEVICE_ATTR(max_microvolts, 0444, regulator_max_uV_show, NULL); 774 + static DEVICE_ATTR_RO(max_microvolts); 775 775 776 - static ssize_t regulator_total_uA_show(struct device *dev, 777 - struct device_attribute *attr, char *buf) 776 + static ssize_t requested_microamps_show(struct device *dev, 777 + struct device_attribute *attr, char *buf) 778 778 { 779 779 struct regulator_dev *rdev = dev_get_drvdata(dev); 780 780 struct regulator *regulator; ··· 788 788 regulator_unlock(rdev); 789 789 return sprintf(buf, "%d\n", uA); 790 790 } 791 - static DEVICE_ATTR(requested_microamps, 0444, regulator_total_uA_show, NULL); 791 + static DEVICE_ATTR_RO(requested_microamps); 792 792 793 793 static ssize_t num_users_show(struct device *dev, struct device_attribute *attr, 794 794 char *buf) ··· 813 813 } 814 814 static DEVICE_ATTR_RO(type); 815 815 816 - static ssize_t regulator_suspend_mem_uV_show(struct device *dev, 817 - struct device_attribute *attr, char *buf) 816 + static ssize_t suspend_mem_microvolts_show(struct device *dev, 817 + struct device_attribute *attr, char *buf) 818 818 { 819 819 struct regulator_dev *rdev = dev_get_drvdata(dev); 820 820 821 821 return sprintf(buf, "%d\n", rdev->constraints->state_mem.uV); 822 822 } 823 - static DEVICE_ATTR(suspend_mem_microvolts, 0444, 824 - regulator_suspend_mem_uV_show, NULL); 823 + static DEVICE_ATTR_RO(suspend_mem_microvolts); 825 824 826 - static ssize_t regulator_suspend_disk_uV_show(struct device *dev, 827 - struct device_attribute *attr, char *buf) 825 + static ssize_t suspend_disk_microvolts_show(struct device *dev, 826 + struct device_attribute *attr, char *buf) 828 827 { 829 828 struct regulator_dev *rdev = dev_get_drvdata(dev); 830 829 831 830 return sprintf(buf, "%d\n", rdev->constraints->state_disk.uV); 832 831 } 833 - static DEVICE_ATTR(suspend_disk_microvolts, 0444, 834 - regulator_suspend_disk_uV_show, NULL); 832 + static DEVICE_ATTR_RO(suspend_disk_microvolts); 835 833 836 - static ssize_t regulator_suspend_standby_uV_show(struct device *dev, 837 - struct device_attribute *attr, char *buf) 834 + static ssize_t suspend_standby_microvolts_show(struct device *dev, 835 + struct device_attribute *attr, char *buf) 838 836 { 839 837 struct regulator_dev *rdev = dev_get_drvdata(dev); 840 838 841 839 return sprintf(buf, "%d\n", rdev->constraints->state_standby.uV); 842 840 } 843 - static DEVICE_ATTR(suspend_standby_microvolts, 0444, 844 - regulator_suspend_standby_uV_show, NULL); 841 + static DEVICE_ATTR_RO(suspend_standby_microvolts); 845 842 846 - static ssize_t regulator_suspend_mem_mode_show(struct device *dev, 847 - struct device_attribute *attr, char *buf) 843 + static ssize_t suspend_mem_mode_show(struct device *dev, 844 + struct device_attribute *attr, char *buf) 848 845 { 849 846 struct regulator_dev *rdev = dev_get_drvdata(dev); 850 847 851 848 return regulator_print_opmode(buf, 852 849 rdev->constraints->state_mem.mode); 853 850 } 854 - static DEVICE_ATTR(suspend_mem_mode, 0444, 855 - regulator_suspend_mem_mode_show, NULL); 851 + static DEVICE_ATTR_RO(suspend_mem_mode); 856 852 857 - static ssize_t regulator_suspend_disk_mode_show(struct device *dev, 858 - struct device_attribute *attr, char *buf) 853 + static ssize_t suspend_disk_mode_show(struct device *dev, 854 + struct device_attribute *attr, char *buf) 859 855 { 860 856 struct regulator_dev *rdev = dev_get_drvdata(dev); 861 857 862 858 return regulator_print_opmode(buf, 863 859 rdev->constraints->state_disk.mode); 864 860 } 865 - static DEVICE_ATTR(suspend_disk_mode, 0444, 866 - regulator_suspend_disk_mode_show, NULL); 861 + static DEVICE_ATTR_RO(suspend_disk_mode); 867 862 868 - static ssize_t regulator_suspend_standby_mode_show(struct device *dev, 869 - struct device_attribute *attr, char *buf) 863 + static ssize_t suspend_standby_mode_show(struct device *dev, 864 + struct device_attribute *attr, char *buf) 870 865 { 871 866 struct regulator_dev *rdev = dev_get_drvdata(dev); 872 867 873 868 return regulator_print_opmode(buf, 874 869 rdev->constraints->state_standby.mode); 875 870 } 876 - static DEVICE_ATTR(suspend_standby_mode, 0444, 877 - regulator_suspend_standby_mode_show, NULL); 871 + static DEVICE_ATTR_RO(suspend_standby_mode); 878 872 879 - static ssize_t regulator_suspend_mem_state_show(struct device *dev, 880 - struct device_attribute *attr, char *buf) 873 + static ssize_t suspend_mem_state_show(struct device *dev, 874 + struct device_attribute *attr, char *buf) 881 875 { 882 876 struct regulator_dev *rdev = dev_get_drvdata(dev); 883 877 884 878 return regulator_print_state(buf, 885 879 rdev->constraints->state_mem.enabled); 886 880 } 887 - static DEVICE_ATTR(suspend_mem_state, 0444, 888 - regulator_suspend_mem_state_show, NULL); 881 + static DEVICE_ATTR_RO(suspend_mem_state); 889 882 890 - static ssize_t regulator_suspend_disk_state_show(struct device *dev, 891 - struct device_attribute *attr, char *buf) 883 + static ssize_t suspend_disk_state_show(struct device *dev, 884 + struct device_attribute *attr, char *buf) 892 885 { 893 886 struct regulator_dev *rdev = dev_get_drvdata(dev); 894 887 895 888 return regulator_print_state(buf, 896 889 rdev->constraints->state_disk.enabled); 897 890 } 898 - static DEVICE_ATTR(suspend_disk_state, 0444, 899 - regulator_suspend_disk_state_show, NULL); 891 + static DEVICE_ATTR_RO(suspend_disk_state); 900 892 901 - static ssize_t regulator_suspend_standby_state_show(struct device *dev, 902 - struct device_attribute *attr, char *buf) 893 + static ssize_t suspend_standby_state_show(struct device *dev, 894 + struct device_attribute *attr, char *buf) 903 895 { 904 896 struct regulator_dev *rdev = dev_get_drvdata(dev); 905 897 906 898 return regulator_print_state(buf, 907 899 rdev->constraints->state_standby.enabled); 908 900 } 909 - static DEVICE_ATTR(suspend_standby_state, 0444, 910 - regulator_suspend_standby_state_show, NULL); 901 + static DEVICE_ATTR_RO(suspend_standby_state); 911 902 912 - static ssize_t regulator_bypass_show(struct device *dev, 913 - struct device_attribute *attr, char *buf) 903 + static ssize_t bypass_show(struct device *dev, 904 + struct device_attribute *attr, char *buf) 914 905 { 915 906 struct regulator_dev *rdev = dev_get_drvdata(dev); 916 907 const char *report; ··· 919 928 920 929 return sprintf(buf, "%s\n", report); 921 930 } 922 - static DEVICE_ATTR(bypass, 0444, 923 - regulator_bypass_show, NULL); 931 + static DEVICE_ATTR_RO(bypass); 924 932 925 933 /* Calculate the new optimum regulator operating mode based on the new total 926 934 * consumer load. All locks held by caller