[bug report] UBI: rename sv to av
Dan Carpenter
dan.carpenter at linaro.org
Mon Jul 17 00:51:04 PDT 2023
Hello MTD dev,
I don't know why this warning is suddenly showing up for ancient code.
drivers/mtd/ubi/attach.c:1790 self_check_ai()
warn: address of NULL pointer 'av'
drivers/mtd/ubi/attach.c
1658 static int self_check_ai(struct ubi_device *ubi, struct ubi_attach_info *ai)
1659 {
1660 struct ubi_vid_io_buf *vidb = ai->vidb;
1661 struct ubi_vid_hdr *vidh = ubi_get_vid_hdr(vidb);
1662 int pnum, err, vols_found = 0;
1663 struct rb_node *rb1, *rb2;
1664 struct ubi_ainf_volume *av;
1665 struct ubi_ainf_peb *aeb, *last_aeb;
1666 uint8_t *buf;
1667
1668 if (!ubi_dbg_chk_gen(ubi))
1669 return 0;
1670
1671 /*
1672 * At first, check that attaching information is OK.
1673 */
1674 ubi_rb_for_each_entry(rb1, av, &ai->volumes, rb) {
1675 int leb_count = 0;
1676
1677 cond_resched();
1678
1679 vols_found += 1;
1680
1681 if (ai->is_empty) {
1682 ubi_err(ubi, "bad is_empty flag");
1683 goto bad_av;
1684 }
1685
1686 if (av->vol_id < 0 || av->highest_lnum < 0 ||
1687 av->leb_count < 0 || av->vol_type < 0 || av->used_ebs < 0 ||
1688 av->data_pad < 0 || av->last_data_size < 0) {
1689 ubi_err(ubi, "negative values");
1690 goto bad_av;
1691 }
1692
1693 if (av->vol_id >= UBI_MAX_VOLUMES &&
1694 av->vol_id < UBI_INTERNAL_VOL_START) {
1695 ubi_err(ubi, "bad vol_id");
1696 goto bad_av;
1697 }
1698
1699 if (av->vol_id > ai->highest_vol_id) {
1700 ubi_err(ubi, "highest_vol_id is %d, but vol_id %d is there",
1701 ai->highest_vol_id, av->vol_id);
1702 goto out;
1703 }
1704
1705 if (av->vol_type != UBI_DYNAMIC_VOLUME &&
1706 av->vol_type != UBI_STATIC_VOLUME) {
1707 ubi_err(ubi, "bad vol_type");
1708 goto bad_av;
1709 }
1710
1711 if (av->data_pad > ubi->leb_size / 2) {
1712 ubi_err(ubi, "bad data_pad");
1713 goto bad_av;
1714 }
1715
1716 last_aeb = NULL;
1717 ubi_rb_for_each_entry(rb2, aeb, &av->root, u.rb) {
1718 cond_resched();
1719
1720 last_aeb = aeb;
1721 leb_count += 1;
1722
1723 if (aeb->pnum < 0 || aeb->ec < 0) {
1724 ubi_err(ubi, "negative values");
1725 goto bad_aeb;
1726 }
1727
1728 if (aeb->ec < ai->min_ec) {
1729 ubi_err(ubi, "bad ai->min_ec (%d), %d found",
1730 ai->min_ec, aeb->ec);
1731 goto bad_aeb;
1732 }
1733
1734 if (aeb->ec > ai->max_ec) {
1735 ubi_err(ubi, "bad ai->max_ec (%d), %d found",
1736 ai->max_ec, aeb->ec);
1737 goto bad_aeb;
1738 }
1739
1740 if (aeb->pnum >= ubi->peb_count) {
1741 ubi_err(ubi, "too high PEB number %d, total PEBs %d",
1742 aeb->pnum, ubi->peb_count);
1743 goto bad_aeb;
1744 }
1745
1746 if (av->vol_type == UBI_STATIC_VOLUME) {
1747 if (aeb->lnum >= av->used_ebs) {
1748 ubi_err(ubi, "bad lnum or used_ebs");
1749 goto bad_aeb;
1750 }
1751 } else {
1752 if (av->used_ebs != 0) {
1753 ubi_err(ubi, "non-zero used_ebs");
1754 goto bad_aeb;
1755 }
1756 }
1757
1758 if (aeb->lnum > av->highest_lnum) {
1759 ubi_err(ubi, "incorrect highest_lnum or lnum");
1760 goto bad_aeb;
1761 }
1762 }
1763
1764 if (av->leb_count != leb_count) {
1765 ubi_err(ubi, "bad leb_count, %d objects in the tree",
1766 leb_count);
1767 goto bad_av;
1768 }
1769
1770 if (!last_aeb)
1771 continue;
1772
1773 aeb = last_aeb;
1774
1775 if (aeb->lnum != av->highest_lnum) {
1776 ubi_err(ubi, "bad highest_lnum");
1777 goto bad_aeb;
1778 }
1779 }
1780
1781 if (vols_found != ai->vols_found) {
1782 ubi_err(ubi, "bad ai->vols_found %d, should be %d",
1783 ai->vols_found, vols_found);
1784 goto out;
1785 }
1786
1787 /* Check that attaching information is correct */
1788 ubi_rb_for_each_entry(rb1, av, &ai->volumes, rb) {
"av" points to the next entry in the loop. It's NULL if we are on the
last entry.
1789 last_aeb = NULL;
--> 1790 ubi_rb_for_each_entry(rb2, aeb, &av->root, u.rb) {
^^^^^^^^^
So it's weird to talk about "&av->root" here.
1791 int vol_type;
1792
1793 cond_resched();
1794
1795 last_aeb = aeb;
1796
1797 err = ubi_io_read_vid_hdr(ubi, aeb->pnum, vidb, 1);
1798 if (err && err != UBI_IO_BITFLIPS) {
1799 ubi_err(ubi, "VID header is not OK (%d)",
1800 err);
regards,
dan carpenter
More information about the linux-mtd
mailing list