Its antibacterial and antiviral properties keep the penis clean and healthy. All mammals produce smegma. Skin cells from the glans of the penis and the inner foreskin are shed throughout life. They escape by working their way to the tip of the foreskin. These escaping discarded skin cells constitute infant smegma.
Adult smegma serves as a protective, lubricating function for the glans.
The foreskin acts as a cover for the glans and produces smegma for a protective coating. This is particularly important if wet diapers are left on too long, since decomposition of the urine can cause irritation of the glans if it is not coated with smegma. When mammals reproduce, smegma is deposited. If smegma contained a carcinogen or even an irritant, then the propagation of the species would be jeopardized. No such phenomenon exists.